Is the srand(time(0)) really makes distribution of values more random? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

Is the srand(time(0)) really makes distribution of values more random?

Without srand(time(0)) 0: 0.099813 1: 0.100125 2: 0.099907 3: 0.100691 4: 0.100209 5: 0.099232 6: 0.100194 7: 0.099684 8: 0.099754 9: 0.100392 with srand(time(0)) : 0:0.100006 1:0.100336 2:0.099907 3:0.100045 4:0.100254 5:0.099686 6:0.099776 7:0.099972 8:0.099982 9:0.100037 https://code.sololearn.com/c297oWG1864l/?ref=app

28th Mar 2018, 12:46 PM
Alex K
Alex K - avatar
1 Antwort
+ 9
srand() doesn't necessarily make the distribution more random. It is used to randomise the seed for the built-in RNG algorithm. Without providing a seed, rand() would simply return the same values for each run. (which, in most cases, would probably not be what you want)
28th Mar 2018, 12:49 PM
Hatsy Rei
Hatsy Rei - avatar