0

I cant understand why srand() is used

24th Jul 2017, 6:06 AM
Gubbala Saisree
Gubbala Saisree - avatar
2 Réponses
+ 6
srand() is used to 'randomise' the built-in RNG algorithm by providing a seed. https://code.sololearn.com/cMUCJqFL1X65/?ref=app
24th Jul 2017, 6:54 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
srand() gives you a random number from a seed value. To get a unique random number each time you run the program, you can pass the tinge as seed value because it keeps changing. Thus you can do srand(time(0)). It is very useful in different situations eg, doing a toss in a game or shuffling something.
24th Jul 2017, 7:26 AM
Hanif Ali
Hanif Ali - avatar