Search code examples
c#random

Crossplatform random number generator


When you need to be able to generate a random number from a seed, and guarantee it be the same number across different versions of the .NET Framework and Mono Framework, as-well as across different architectures (x86, x64), what do you do?

I'm presently considering storing millions of random bytes in a file for use as a temporary solution to this problem, but I think there's probably a better way (hopefully not too much more complicated).


Solution

  • If you need a truly portable implementation, the best option would probably be to just use a custom random number generator, such as this Mersenne Twister implementation or Colin Green's Fast Random Number Generator. By controlling the implementation, you can guarantee that you'll get the same results given the same seed on any platform.