[Python-ideas] Pre-PEP Adding A Secrets Module To The Standard Library
Steven D'Aprano
steve at pearwood.info
Mon Sep 21 20:05:08 CEST 2015
On Mon, Sep 21, 2015 at 12:51:13PM -0500, Tim Peters wrote:
> [Tim]
> >> ...
> >> No attempt to be minimal here. More-than-less "obvious" is more important:
> >>
> >> Bound methods of a SystemRandom instance
> >> .randrange()
> >> .randint()
> >> .randbits()
> >> renamed from .getrandbits()
> >> .randbelow(exclusive_upper_bound)
> >> renamed from private ._randbelow()
> >> .choice()
>
> [Steven D'Aprano <steve at pearwood.info>]
> > While we're bike-shedding,
>
> I refuse to bikeshed on this. I posted a concrete proposal just to
> enrage others into it ;-) So I'll just sketch my thinking:
Consider me enraged. Hulk smash puny humans!
[...]
> > When would somebody use randbelow(n) rather than randrange(n)?
>
> For the same reason they'd use randbits(n) instead of randrange(1 <<
> n) ;-) That is, familiarity and obviousness.
Okay, that makes sense.
> > Are there use-cases for a strong random float between 0 and 1? If
> > so, is it sufficient to say secrets.randbelow(sys.maxsize)/sys.maxsize,
> > or should we offer secrets.random() and/or secrets.uniform(a, b)?
>
> I don't know of any "security use" for random floats. But if you want
> to add a recipe to the docs, point them to SystemRandom.random
> instead. That gets it right.
Good enough for me.
--
Steve
More information about the Python-ideas
mailing list