Reputation: 9194
If I am using the Random class in .Net(4.5) and I am always using the same seed to generate 1000 numbers is there a chance that on a different machine (with diff chipset / number of cores, etc) that my 1000 numbers could be different? I don't see how that could be, but was told by one of my colleagues that we need to be aware that they could be. The testing I have done seems to always be consistent. Just concerned that I could have a scenario where I could get different numbers. I could understand it being different if I was trying to parallize the generation or something.
int seed = 99;
var random = new Random(seed);
for (int i = 0; i < 1000; i++)
random.Next();
Upvotes: 2
Views: 315
Reputation: 2839
According to this link, you will get the same sequence in all cases for .Net 4.5 Not sure if that applies to different versions of .Net framework (agreeing with previous answer).
"Providing an identical seed value to different Random objects causes each instance to produce identical sequences of random numbers."
Upvotes: 3
Reputation: 1062865
Between different PCs running the same framework sounds unlikely (meaning: you can reasonably expect the same sequences) - but MS do reserve the right to change the implementation. MSDN states:
The implementation of the random number generator in the Random class is not guaranteed to remain the same across major versions of the .NET Framework. As a result, your application code should not assume that the same seed will result in the same pseudo-random sequence in different versions of the .NET Framework.
So: if you need a stronger guarantee: use your own PRNG implementation. There are plenty of such to choose from.
Upvotes: 8