Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
165 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...