Jump to content
RaelB

Looking for thread-safe repeatable random sequence generator

Recommended Posts

I'm wanting to generate a repeatable random number/character sequence based on a given seed value. Using the in built Randomize function with global RandSeed can do this, but is not thread-safe. Any recommendation for open source/light weight solution?

Thanks

Share this post


Link to post

It is utterly trivial to make such a thing using the exact same code as found in Random. You make a record that contains a seed and you add a method that uses that seed to generate the next sample, and then update the seed. 

 

If you have specific requirements for the properties of the PRNG then you may find the LCG used by Random doesn't meet them. In which case you'd need to decide what your requirements are. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×