7

I'm looking for an algorithm to generate random numbers from a given seed but with the particular requirement that it will always generate the same sequence of number regardless of the underlying computer architecture or language implementation.

I already know of Mersenne Twister, however, the numbers it generates differ when using different implementations (i.e. C MT vs Javascript MT).

Do algorithms with this property exist? Also, I don't need a state-of-the-art RNG, I don't even need it to be cryptographically secure, I just want to drive a "random" simulation on one place and have it follow the same behavior on a different implementation.

Ale Morales
  • 2,728
  • 4
  • 29
  • 42
  • 1
    Have you read the [wikipedia article](http://en.wikipedia.org/wiki/Pseudorandom_number_generator)? A [linear congruential generator](http://en.wikipedia.org/wiki/Linear_congruential_generator) might meet your needs and is easy to implement on virtually every platform/language to produce identical results. There are of course other, possibly better, choice as the articles discuss. – President James K. Polk Dec 24 '14 at 19:33
  • 2
    Mersenne Twister (or more specifically MT19937) is a standard. All correct implementations produce the same results. Sounds like one of your implementations is wrong. – ntoskrnl Dec 24 '14 at 22:39
  • The seeding algorithm for Mersenne Twister has changed over time. Moreover, there is no default seed value in the code posted by Takuji Nishimura and Makoto Matsumoto. – user515430 Dec 25 '14 at 02:17
  • Do you use floating point numbers, or just integers? – CodesInChaos Dec 25 '14 at 09:58
  • 1
    In practice, MT implementations return different values. But thanks GregS, an LCG would suffice my needs. I was looking for something that was already available but xorshift's algos look extremely simple to implement and have all the properties I'm looking for. I'll go that way. – Ale Morales Dec 25 '14 at 15:14
  • @CodesInChaos anuone would do it – Ale Morales Dec 25 '14 at 15:15
  • [Obligatory XKCD](http://xkcd.com/221/) - seems it will meet your stated requirements. – rolfl Feb 17 '15 at 18:36

1 Answers1

2

If you don't need a cryptographicly secure RNG then MT or LCG would do. Still, some stream ciphers are pretty easy to implement in many languages, or already available, so these are viable paths. All of these are deterministic, same seed results in the same random numbers, and quite fast.

Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166