I don't recall seeing any program call srand
with anything but srand(time(NULL))
. Under what circumstances would one call srand
with some other value?
I don't recall seeing any program call srand
with anything but srand(time(NULL))
. Under what circumstances would one call srand
with some other value?
The function rand()
doesn't return random numbers. It's a pseudo random generator instead. That's why you get the same sequence of numbers when you call srand()
with the same argument. Calling srand()
with the current time is the actually only random item. The numbers you get from rand()
are just scrambled.
You will call srand()
with a predictable or constant value when you want to replay
a sequence, debug a functionality with the same sequence again and again.