How do I generate random floats in C++?
I thought I could take the integer rand and divide it by something, would that be adequate enough?
For C++, it can generate real float numbers within the range specified by dist
variable
#include //If it doesnt work then use #include
#include
using namespace std;
typedef std::tr1::ranlux64_base_01 Myeng;
typedef std::tr1::normal_distribution Mydist;
int main() {
Myeng eng;
eng.seed((unsigned int) time(NULL)); //initializing generator to January 1, 1970);
Mydist dist(1,10);
dist.reset(); // discard any cached values
for (int i = 0; i < 10; i++)
{
std::cout << "a random value == " << (int)dist(eng) << std::endl;
}
return (0);
}