0

Can anybody shed light on the impact of using a different value here?

CLR System.Random (random.cs, 61) appears to cite the algorithm used

//This algorithm comes from Numerical Recipes in C (2nd Ed.)

and uses this line of code (random.cs, 80)

 inextp = 21;    
 
 

However, looking at that apparent algorithm being used (Numerical Recipes in C, 283)

 inextp=31; The constant 31 is special; see Knuth.

(Knuth 124) talks about the area of distribution under a curve for random number generation being broken into 31 rectangles.

I'm no math whiz and trying to follow through this algorithm makes my brain hurt a bit.

random.cs. Microsoft Reference Source, .NET Framework 4.8 https://referencesource.microsoft.com/#mscorlib/system/random.cs

Press, Teukolsky, et. al., Numerical Recipes in C : The Art of Scientific Computing, 2nd ed. https://www.cec.uchile.cl/cinetica/pcordero/MC_libros/NumericalRecipesinC.pdf

Donald Knuth, The Art of Computer Programming 3rd ed., vol. 2 Seminumerical Alogirthms https://seriouscomputerist.atariverse.com/media/pdf/book/Art%20of%20Computer%20Programming%20-%20Volume%202%20(Seminumerical%20Algorithms).pdf

Rex Henderson
  • 412
  • 2
  • 7
  • As far as I know, it's not a conscious decision, but rather, a typo. I can't find a more authoritative source right now, so not posting this as an answer, but as a comment. – milleniumbug Sep 13 '20 at 20:10
  • 2
    I found an archived link to a bug report pertaining to this specific issue. https://web.archive.org/web/20160120184840/http://connect.microsoft.com/VisualStudio/feedback/details/634761/system-random-serious-bug – milleniumbug Sep 13 '20 at 20:16
  • In short there are known issues with Random (more than 1), and the distribution is commonly talked about on github and other places. They will seemingly never be fixed (even in .net core), for various reasons, mainly because changing the algorithm may implement too much of a breaking change for code bases that rely on a seeds. Additionally there are better algorithms in the BCL. Personally, reading the reasons why it should be fixed is disheartening, and always has certain actors saying blah blah blah, lets not, and nothing progresses... – TheGeneral Sep 13 '20 at 21:26
  • If you are interested in the actual mechanics of the generator, this is probably more of a statistics / math question. If you are interested in the actual problems with the C# generator, it can be found in various places on the internet. If you are interested in better implementations in C#, once again there are many, i believe even Eric Lippert and co have blogs floating around this – TheGeneral Sep 13 '20 at 21:41
  • Great info guys. Much thanks. My curiosity is satisfied. – Rex Henderson Sep 14 '20 at 17:15

0 Answers0