gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 04:08:13 24 4
gpt4 key购买 nike

关于 .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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com