Python是如何产生随机数的? [英] How does Python generate random numbers?

查看:55
本文介绍了Python是如何产生随机数的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我应该在 Python 中使用 os.urandom()SystemRandom 来获取安全"伪随机数.

I understand that I should use os.urandom() or SystemRandom in Python for 'secure' pseudo-random numbers.

但是 Python 是如何在逻辑上生成这些随机数的呢?

But how does Python generate these random numbers logically?

还有没有办法在 Python 中生成一个比其他数字更随机"的数字?

Also is there a way to generate a number in Python that is 'more random' than others?

推荐答案

对于安全"随机数,Python 实际上并不生成它们:它从操作系统获取它们,操作系统有一个特殊的驱动程序,可以从各种真实世界的来源,例如击键和磁盘搜索之间的时间变化.

For "secure" random numbers, Python doesn't actually generate them: it gets them from the operating system, which has a special driver that gathers entropy from various real-world sources, such as variations in timing between keystrokes and disk seeks.

这篇关于Python是如何产生随机数的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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