为什么随机类不是真正随机的?
我已经在留言板上读到了它-Random
类并不是真正随机的.它是使用数学公式以可预测的方式创建的.
I've read about it on a message board - Random
class isn't really random. It is created with predictable fashion using a mathematical formula.
这是真的吗?如果是这样,Random
并不是随机的吗?
Is it really true? If so, Random
isn't really random??
正如其他人已经说过的那样,Random根据某些种子值创建伪随机数.知道.NET类Random
具有两个构造函数可能会有所帮助:
As others have already said, Random creates pseudo-random numbers, depending on some seed value. It may be helpful to know that the .NET class Random
has two constructors:
Random(int Seed)
创建具有给定种子值的随机数生成器,如果您希望程序的行为可重现,则很有用.另一方面,
creates a random number generator with a given seed value, helpful if you want reproducible behaviour of your program. On the other hand,
Random()
使用日期时间取决于种子值创建一个随机数生成器,这意味着几乎每次您再次启动程序时,它都会生成不同的(伪)随机数序列.
creates a random number generator with date-time depending seed value, which means, almost every time you start your program again, it will produce a different sequence of (pseudo-)random numbers.