Cross-platform cross-language cross-everything actually deterministic random number generator
Asked Answered
R

1

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.

Rollet answered 24/12, 2014 at 19:5 Comment(7)
Have you read the wikipedia article? A 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.Reck
Mersenne Twister (or more specifically MT19937) is a standard. All correct implementations produce the same results. Sounds like one of your implementations is wrong.Upbeat
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.Voluptuous
Do you use floating point numbers, or just integers?Hedden
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.Rollet
@Hedden anuone would do itRollet
Obligatory XKCD - seems it will meet your stated requirements.Tye
B
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.

Belldas answered 29/12, 2014 at 15:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.