Why does rand() keep giving me same number? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
- 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
1 Antwort
+ 4
You need to seed random once before you use it. srand(time(NULL));
29th Apr 2020, 11:07 AM
ChaoticDawg
ChaoticDawg - avatar