Does every machine generate same result of random number by using the same seed?

I would expect any one implementation to give the same sequence for the same seed, but there may well be different implementations involved. For example, an "online C# compiler" may well end up using Mono, which I'd expect to have a different implementation to the one in .NET.

I don't know whether the implementations have changed between versions of .NET, but again, that seems entirely possible.

The documentation for the Random(int) constructor states:

Providing an identical seed value to different Random objects causes each instance to produce identical sequences of random numbers.

... but it doesn't specify the implications of different versions etc. Heck, it doesn't even state whether the x86 and x64 versions will give the same results. I'd expect the same results within any one specific CLR instance (i.e. one process, and not two CLRs running side-by-side, either*.

If you need anything more stable, I'd start off with a specified algorithm - I bet there are implementations of the Mersenne Twister etc available.


It isn't specified as making such a promise, so you should assume that it does not.

A good rule with any specification, is not to make promises that aren't required for reasonable use, so you are freer to improve things later on.

Indeed, Random's documentation says:

The current implementation of the Random class is based on Donald E. Knuth's subtractive random number generator algorithm.

Note the phrase "current implementation", implying it may change in the future. This very strongly suggests that not only is there no promise to be consistent between versions, but there is no intention to either.

If a spec requires consistent pseudo-random numbers, then it must specify the algorithm as well as the seed value. Indeed, even if Random was specified as making such a promise, what if you need a non-.NET implementation of all or part of your specification - or something that interoperates with it - in the future?


This is probably due to different framework versions. Have a look at this

Tags:

C#

.Net

Random

Seed