[Python-ideas] Globally configurable random number generation

Donald Stufft donald at stufft.io
Mon Sep 14 15:51:29 CEST 2015

On September 14, 2015 at 9:33:27 AM, Nick Coghlan (ncoghlan at gmail.com) wrote:
> * seedable
> * seedless
> * system
> These terms are chosen to make sense to folks that have *no idea*
> about the way different kinds of random number generator work and how
> that affects their security properties, but do know whether or not
> they need to be able to pass in a particular fixed seed in order to
> regenerate the same series of outputs.

I don't love the "seedable" and "seedless" names here, but I don't have a
better suggestion for the userspace CSPRNG one because it's security properties
are a bit nuanced. People doing security sensitive things like generating keys
for cryptography should still use something based on os.urandom, so it's mostly
about providing a safety net that will "probably" [1] be safe. Probably
something like random.ProbablySecureRandom is a bad name :)

> * provide a random.set_default_instance() API that makes it possible
> to specify the instance used by the module level methods

I think this particular bit is a bad idea, it makes an official API that makes
it really hard for an auditor to come into a code base and determine if the use
of random is correct or not. Given that going back to the MT based algorithm is
fairly trivial (and could even be mechanical) what's the long ter benefit here?

[1] The safety of userspace CSPRNGs is a debated topic by security experts,
    however I think any of them would be hard pressed to think it's a bad idea
    to have a userspace CSPRNG as a safety net for folks who, for whatever
    reason, didn't know to use os.urandom/random.SystemRandom and instead to
    make them more likely to be safe, or at the very least, harder to attack.

Donald Stufft
PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA

More information about the Python-ideas mailing list