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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.