[Python-ideas] Should our default random number generator be secure?

Tim Peters tim.peters at gmail.com
Thu Sep 10 18:10:26 CEST 2015

[Brett Cannon <brett at python.org>]
> ...
> I see a third: rename random.random() to be be something that gets the point
> across it is not crypto secure and then stop at that,
> ...
> Theo's key issue is misuse of random.random(), ...
> ...
> But then again that won't help with all of the other functions in
> the random module that implicitly use random.random() (if that even matters;
> not sure if the helper functions in the module have any crypto use that
> would lead to their misuse).

The most likely "misuses" in idiomatic Python (not mindlessly
translated low-level C) involve some spelling of getting or using
random integers, like .choice(), .randrange(), .randint(), or even
.sample() and .shuffle().  At least in Python 3, those don't normally
ever invoke .random() (neither directly nor indirectly) - they
normally use the (didn't always exist) "primitive" .getrandbits()
instead (indirectly via the private ._randbelow()).

So if something here does need to change, it's all or nothing.

> Oh, and there is always the nuclear 4th option and we just deprecate the
> random module. ;)

I already removed it from the repository.  Deprecating it would be a
security risk, since it would give hackers information about our
future actions ;-)

More information about the Python-ideas mailing list