为什么随机类不是真正随机的? [英] Why is Random class isn't really random?

查看:190
本文介绍了为什么随机类不是真正随机的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在留言板上读到了它-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.

这篇关于为什么随机类不是真正随机的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆