c# - .NET 中随机类实现的质量如何?

标签 c# .net random

关于 .NET Framework 4.6 中 Random 类的实现,我有两个问题(可用代码 here ):

  1. 在构造函数末尾将 Seed 参数设置为 1 的基本原理是什么?它似乎是从 Numerical Recipes in C(第 2 版) 中复制粘贴的,其中它有一定的意义,但它在 C# 中没有任何内容。

  2. Numerical Recipes in C (2nd Ed.) 一书中直接指出,inextp 字段设置为值 31 因为:

The constant 31 is special; see Knuth.

但是,在 .NET 实现中,此字段设置为值 21。为什么?除此细节外,其余代码似乎与书中的代码非常相似。

最佳答案

关于 intexp 问题,这是一个错误,Microsoft has acknowledged and refused to fix由于向后兼容性问题。

Indeed, you have discovered a genuine problem with the Random implementation. We have discussed it within the team and with some of our partners and concluded that we unfortunately cannot fix the problem right now. The reason is that some applications rely on the fact that when initialised with the same seed, the generator produces the same pseudo random sequence. Even if the change is for the better, it will break the applications that made this assumption once they have migrated to the “fixed” version.

关于c# - .NET 中随机类实现的质量如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31916419/

相关文章:

c++ - 如何设置时间差输出数字1秒

JavaScript - 循环遍历一次仅显示一个的非重复值

c# - 如何使用 Magick.Net 调整 jpeg 质量

c# - StaticResource 标记扩展与 System.Windows.Application.FindResource

c# - 如何使用 WebHttpBinding 在 WCF 的 uri 路径中使用强类型参数

c# - ASP.NET MVC 查询的通用处理程序

javascript - 随机划分数组内的一个值

c# - 当我单击 CheckBox 时,Wpf PasswordBox 必须显示字符

c# - ASP :Label, span 和 javascript elementbyId 访问

c# - 在 json.net 中转换为 DateTime