Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the reason Microsoft don't guarantee the implementation of Random class to remain the same across version of .NET? [closed]

Quoted from online documentation:

Notes to Callers: 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.

What is the reason Microsoft don't guarantee the implementation of Random class to remain the same across version of .NET? More specifically, what is the reason Microsoft don't guarantee the same seed to produce the same sequence of random numbers across major version of .NET framework?

like image 995
kiss my armpit Avatar asked Jan 02 '14 16:01

kiss my armpit


2 Answers

Because generating predictable numbers is not the purpose of the Random class.

It's purpose is to generate pseudo-random numbers:

Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet certain statistical requirements for randomness.

The way the numbers are generated is an implementation detail. If they find a better or faster way to do it, they want to reserve the right to change it, and give you the fair warning not to produce code that relies on it.

like image 142
Rotem Avatar answered Sep 20 '22 03:09

Rotem


There's a problem with the highly upvoted post. The Random class most certainly generates predictable numbers. From the documentation for the Random(Int32) constructor:

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

What Microsoft does not want to promise is that this sequence will be identical in another .NET Framework release. There's a good reason for that, they cannot be sure if the algorithm they used is completely free of flaws. The kind that makes code that uses the Random class vulnerable or liable to generate biased results. Odds are very low but not zero.

There is precedent for this, the most infamous case was a problem with the random generator that IBM used in their mainframe software, called RANDU. Quoted as "Widely considered to be one of the most ill-conceived random number generators ever designed". It has pretty obvious flaws once analysts started to take a better look at it. First flagged in 1963, it was still widely used in the 1970s.

like image 27
Hans Passant Avatar answered Sep 23 '22 03:09

Hans Passant