why cant i generate a random number of type double?

Mar 27, 2013 at 8:05pm
hey guys i wrote this code and i want to generate randome numbers of type double. i dont know how to do that.
it keeps giving me an error saying illegal type operand has type double. any idea how to do that? thank you in advance
Last edited on Mar 27, 2013 at 8:09pm
Mar 27, 2013 at 8:13pm
double rand = (double)rand() / (double)rand();
Mar 27, 2013 at 8:13pm
random numbers of type double are normally generated with std::uniform_real_distribution and similar functions:
http://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution
http://cplusplus.com/reference/random/uniform_real_distribution/

You'd have to show your code to get help with your specific error.
Mar 27, 2013 at 8:19pm
static_cast<double>(non-double variable)

This will turn an int into a double.
Mar 27, 2013 at 8:44pm
thank you guys :)
Topic archived. No new replies allowed.