Whats the difference between os.urandom() and random?

前端 未结 2 1315
面向向阳花
面向向阳花 2020-12-29 12:06

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

Warning: The pseudo-random generators of this module should not b

2条回答
  •  北海茫月
    2020-12-29 12:42

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

    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 on the other hand cannot be seeded and draws its source of entropy from many unpredictable sources, making it more random.

    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.

提交回复
热议问题