• Advertisement
Sign in to follow this  

Seeding the random number generator in <cstdlib>

This topic is 660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys,

 

Various sources that I've researched have suggested that srand () should be called exactly once (usually at the beginning of the program) to initialize the PRNG. I'm not thinking far enough ahead to see the problem associated with reseeding the PRNG by calling srand () multiple times. Can anyone enlighten me?

Edited by nGamer

Share this post


Link to post
Share on other sites
Advertisement
If you reseed it repeatedly you're making it less deterministic. This is a good thing if you want it to be unpredictable but if you want predictable random sequences (e.g. for synchronised peer to peer network play like in an rts, debugging, etc) then you should seed exactly once with a known constant number.

Note that the rand function in most c libraries isn't that good and doesn't produce a good spread of random figures, if this is important to you, e.g. for a card game look into marsienne twister or similar Instead.

Hope this helps!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement