+ 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
1 Odpowiedź
+ 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)