- 1

Why does rand() keep giving me same number?

I have been using this function to print a number that would be randomly generated in c++. However, I keep on getting 41 every time it complies. cout<<rand()%100;

29th Apr 2020, 11:04 AM
Prashant Pant
Prashant Pant - avatar
2 Réponses
+ 4
You need to seed random once before you use it. srand(time(NULL));
29th Apr 2020, 11:07 AM
ChaoticDawg
ChaoticDawg - avatar