This question already has an answer here:
- How to generate a random number in C? 22 answers
I'm having trouble generating a new set of random numbers each time I run the program back again...
I'm using
rand() % 2 + 1;
in a loop, and it's generating multiple random numbers just fine. However, when the program runs again, the same "random" numbers result in. They're fixed to the memory. Hence I tried calling:
srand(time(NULL));
But this time it is generating the same number for each iteration in the entire loop!
How can I solve this problem, please?
Aucun commentaire:
Enregistrer un commentaire