os.urandom()和random之间有什么区别? [英] Whats the difference between os.urandom() and random?

查看:636
本文介绍了os.urandom()和random之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在随机模块python 页面(此处链接)上,存在此警告:

On the random module python page (Link Here) there is this warning:

警告:出于安全目的,不应使用此模块的伪随机数生成器.如果您使用os.urandom()或SystemRandom 需要加密安全的伪随机数生成器.

Warning: The pseudo-random generators of this module should not be used for security purposes. Use os.urandom() or SystemRandom if you require a cryptographically secure pseudo-random number generator.

  • 那么os.urandom()和random之间有什么区别?

    • So whats the difference between os.urandom() and random?

      一个比另一个更接近真正的随机性吗?

      Is one closer to a true random than the other?

      在非加密实例中,安全随机是否会过大?

      Would the secure random be overkill in non-cryptographic instances?

      python中还有其他随机模块吗?

      Are there any other random modules in python?

      推荐答案

      您可以阅读有关加密安全RNG的区别在Crypto.SE 的精彩解答中.

      You can read up on the distinction of cryptographically secure RNG in this fantastic answer over at Crypto.SE.

      random和系统RNG(例如urandom)之间的主要区别是用例之一. random实现确定性PRNG.在某些情况下,您需要这些.例如,当您有一个要测试的带有随机元素的算法,并且您需要这些测试是可重复的.在这种情况下,您需要确定的PRNG,您可以种子.

      The main distinction between random and the system RNG like urandom is one of use cases. random implements deterministic PRNGs. There are scenarios where you want exactly those. For instance when you have an algorithm with a random element which you want to test, and you need those tests to be repeatable. In that case you want a deterministic PRNG which you can seed.

      urandom无法播种,并且从许多不可预测的来源中提取其熵源,从而使其更具随机性.

      urandom on the other hand cannot be seeded and draws its source of entropy from many unpredictable sources, making it more random.

      True 随机是另外一回事,您需要物理性的随机源,例如可以测量原子衰减的事物.从物理意义上讲,这确实是随机的,但是对于大多数应用程序来说却通常会显得过大.

      True random is something else yet and you'd need a physical source of randomness like something that measures atomic decay; that is truly random in the physical sense, but usually overkill for most applications.

      这篇关于os.urandom()和random之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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