[Python-ideas] Globally configurable random number generation

Sturla Molden sturla.molden at gmail.com
Mon Sep 14 16:21:11 CEST 2015


On 14/09/15 15:43, Stefan Krah wrote:

> These are sane, unambiguously named APIs. I wish Python had more
> of those.  If people must have their CSPRNG, please let's leave
> the random module alone and introduce a crypto module like Go.

In a perfect world, every programmer would know the difference between 
PRNGs for numerical simulation and entropy sources for cryptography.

Those that do will still use os.urandom or just read from /dev/urandom 
or /dev/random for cryptography.

Those that do know the need for mathematical precision when simulating 
samples from a given distribution. Those that do know the need for a 
fixed seed because a Monte Carlo simulation should be exactly 
reproducible in a scientific context.

The problem is users who have no idea that the Mersenne Twister is 
constructed for producing random deviates that are great for numerical 
simulation -- and that the Mersenne Twister is very weak for cryptography.

Using os.urandom as default entropy source has the opposite effect. It 
is not constructed for being mathematically precise, it is slow, and it 
does not allow for a fixed seed and exact reproducibility.

Whatever we do there are someone who are going to shoot their leg off.

A crypto module would perhaps be great, but it does not solve anything. 
Someone who uses random.random instead of os.urandom is likely to use 
random.random instead of a PRNG in a crypto module as well. Mostly this 
is about propagating knowledge of random number generators to new 
developers and science students.


Sturla




More information about the Python-ideas mailing list