how can i take out a double random number in between 5.0 to 15.0? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

8th Sep 2017, 7:24 AM
Nguyên Triệu
Nguyên Triệu - avatar
4 Answers
+ 9
note: aklex's answer is the preferable method if you have have access to a c++11 compiler.
8th Sep 2017, 8:04 AM
jay
jay - avatar
8th Sep 2017, 7:58 AM
jay
jay - avatar
+ 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"; }
8th Sep 2017, 8:02 AM
aklex
aklex - avatar