views:

161

answers:

4

Hello,

I am looking for a way to generate pseudo random number sequences that will yield identical sequence results for a given seed across any platform. I am assuming that rand()/srand() is not going to be consistent (I could easily be wrong about this assumption).

A: 

The easiest way would be to write a random number generator yourself, but using a library that is released for different platforms and is guaranteed to give the same results could also work.

I doubt rand()/srand() are consistent, but I don't know it.

schnaader
+9  A: 

Something like a Mersenne Twister (from Boost.Random) is deterministic.

rlbond
A: 

A quickly googled reference says:

Two different initializations with the same seed, instructs the pseudo-random generator to generate the same succession of results for the subsequent calls to rand in both cases.

But the question remains. I assume the above spec only applies to RNGs within the same process. It most likely doesn't specify anything about cross-platform or cross-compiler things. Your best bet is probably to find a library that is available for all desired platforms. Then you should be reasonably safe that if seeded with the same value they return the same sequence of numbers.

n3rd
I believe this refers to he behavior of any particular implementation of `rand()`, and does not provide any cross-compiler or cross-platform assurance. Moreover, with built-in PRNGs you risk all kinds of unwanted properties. Use a library with a PRNG known to be appropriate for your needs.
dmckee
+6  A: 

Knuth has released into the public domain C (and FORTRAN) source code for the pseudo-random number generator described in section 3.6 of The Art of Computer Programming.

las3rjock