vendredi 9 février 2018

Generating a random number between [0,1) c++

I'm trying to generate a random number that's uniformly distributed between [0,1) and I have tried uniform_real_distribution but I don't know exactly how that works. I have this code below but it keeps generating close to the same numbers every time ~.456

void RandomNumber()
{
srand(time(0));
double number=(double)rand()/((double)RAND_MAX+1);
cout<<"RANDOM NUMBER: "<<number<<endl;
}




Aucun commentaire:

Enregistrer un commentaire