Oh nice, thanks, I missed this news for .NET 6.
I've used Mersenne Twister in the past for an app where the RNG pool
didn't need to be cryptographically secure but the algorithm did have to
be explicitly specified in the deliverable.
Also, interesting detail in the implementation as noted - if you just
use the Random directly, or use the new Random.Shared thread safe
instance you get xoshiro256**. However, if you seed Random, or derive
from it then it possibly becomes a breaking change and you get the old
behaviour: https://source.dot.net/#System.Private.CoreLib/Random.cs
There doesn't seem to be a way to explicitly opt-in or even seed the new
PRNG implementation though, so looks like it's been done as purely
performance optimisation, which is interesting.
-Tony
On 1/07/2022 11:22, Greg Keogh via ozdotnet wrote:
TGIF folks, FYI - I discovered by accident yesterday in this article
<https://blogs.siliconorchid.com/post/coding-inspiration/randomness-in-dotnet/>
that the algorithm used by the Random class has changed. Historically
it has used the Knuth subtractive algorithm
<https://www.informit.com/articles/article.aspx?p=2221790>, which is
old and respected, and reasonably simple. It holds its internal state
in a seeded int[56] array (I don't know how it scores on cruel tests
like BigCrush <https://en.wikipedia.org/wiki/TestU01>).
It's been replaced with one of the set of new *xoroshiro* algorithms,
which I didn't know about until yesterday. The code is so short that
you can't believe they actually work and produce results that pass
tests that even some of the famous ones like Mersenne Twister can
fail. I'm just amazed by the brevity and quality
<https://prng.di.unimi.it/> (C code links top-right).
ILSpy shows how Random has been completely rejigged to use the new
algorithm or fallback to the internal Net5CompatDerivedImpl class.
/Greg K/