Jump to content
  • Advertisement
Sign in to follow this  
Alundra

Random Number Generator Seed Initialization

This topic is 993 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

Hi,

I always used a global uint32 seed in the anonymous namespace.

Is it better to have each time a seed initialized in the constructor of random number generator and instance each time needed ?

Thanks

Share this post


Link to post
Share on other sites
Advertisement

Having a per-instance seed allows for things like procedurally generated worlds where the co-ordinates are used to generate a seed, while still allowing a separate per-session random instance to control events. A global value also impacts on thread safety.

 

As an example, in C++ the classic std::rand() uses a global seed initialised by std::srand(), where as the newer C++ random generators are instance oriented.

Share this post


Link to post
Share on other sites

It depends on what you're trying to do with what.

 

If you're only ever going to use a single LCG PRNG, then if you want it to act like a global variable, go ahead and use a global variable as its seed.

 

If you want to use something more sophisticated than a single 32-bit LCG, like a lagged Fibonacci or a Mersenne Twister PRNG, then a 32-bit initialization vector is insufficient to start with.

 

If you want to use several different PRNGs in an application, how could a single 32-bit initialization vector ever help you?

 

If you're relying on a single 32-bit initialization vector in the global namespace to be uninitialized to use as a seed value for any PRNG, you are in for a quality debugging treat.

 

Initializing an initialization vector in the constructor of a PRNG object makes no sense.  You want to pass the initialization vector in to the constructor so it can use it to initialize the PRNG.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!