@teo-tsirpanis commented on Sat Oct 15 2016
According to MSDN documentation, the Random class is using
a modified version of Donald E. Knuth's subtractive random number generator algorithm.
This algorithm is somewhat obscure. I have found only this paper that can be said that refers to this algorithm.
Therefore, I propose a change of the default RNG in Random class to the Permuted Cogruential Generator(PCG). According to its site, PCG is:
- More difficult to predict
- Smaller both in code size (
InternalSample will be only five lines of code and Random's constructor will be another five lines)
and in memory usage (just 16 bytes in comparison with the 232 bytes the existing RNG uses)
- More statistically random
It can also provide some other useful features.
There is a more detailed comparison of PCG and other RNGs here.
I submitted dotnet/coreclr#7477 to apply these changes, but I was told to temporarily close it and to open an issue instead for further discussion.
The implementation is based on this one.
It has also added some constructors to Random class that allow it to be seeded with the longer ulong seeds PCG allows. It also implements multiple codebooks. The original constructors are retained, so I guess this isn't a breaking API change.
@teo-tsirpanis commented on Sat Oct 15 2016
According to MSDN documentation, the
Randomclass is usingThis algorithm is somewhat obscure. I have found only this paper that can be said that refers to this algorithm.
Therefore, I propose a change of the default RNG in
Randomclass to the Permuted Cogruential Generator(PCG). According to its site, PCG is:InternalSamplewill be only five lines of code andRandom's constructor will be another five lines)and in memory usage (just 16 bytes in comparison with the 232 bytes the existing RNG uses)
It can also provide some other useful features.
There is a more detailed comparison of PCG and other RNGs here.
I submitted dotnet/coreclr#7477 to apply these changes, but I was told to temporarily close it and to open an issue instead for further discussion.
The implementation is based on this one.
It has also added some constructors to
Randomclass that allow it to be seeded with the longerulongseeds PCG allows. It also implements multiple codebooks. The original constructors are retained, so I guess this isn't a breaking API change.