+ 1
how can i take out a double random number in between 5.0 to 15.0?
randomly take out a number between two given numbers
4 Réponses
+ 9
note: aklex's answer is the preferable method if you have have access to a c++11 compiler.
+ 8
c++11 version: https://stackoverflow.com/a/9324796
+ 4
#include <iostream>
#include <random>
int main()
{
std::uniform_real_distribution<double> uniform(5.0, 15.0);
std::random_device device;
std::mt19937 mt(device());
double a = uniform(mt);
std::cout << a << "\n";
}