dimanche 20 septembre 2015

Random number generator confuses with srand function

I want to learn why my code is not working as I expect. I mean I want to generate a double number between 0 and 1 and I have learnt that when I use (double)rand() / RAND_MAX, it works well. However I read that srand(time(NULL)) changes each generated random number every time I compile. However When I use them together the program generates same random number all the time. Why does this happen? Thanks.

Here is my code:

//srand(time(NULL));
number = (double)rand() / (double)RAND_MAX;




Aucun commentaire:

Enregistrer un commentaire