[Python-Dev] PEP 506 secrets module
Nick Coghlan
ncoghlan at gmail.com
Tue Oct 20 05:11:33 EDT 2015
More information about the Python-Dev mailing list
Tue Oct 20 05:11:33 EDT 2015
- Previous message (by thread): [Python-Dev] PEP 506 secrets module
- Next message (by thread): [Python-Dev] PEP 506 secrets module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 16 October 2015 at 12:04, Steven D'Aprano <steve at pearwood.info> wrote: > On Fri, Oct 16, 2015 at 08:57:24AM +0200, Victor Stinner wrote: >> I don't like the idea how having two functions doing *almost* the same >> thing: randint() and randrange(). There is a risk that these functions >> will be misused. I consider that I know some stuff on PRNG but I'm >> still confused by randint() and randrange(). Usually, I open python >> and type: >> >> >>> x=[s.randrange(1,6) for n in range(100)] >> >>> min(x), max(x) >> (1, 5) > > Wouldn't help(randrange) be easier? :-) > > Choose a random item from range(start, stop[, step]). > > This fixes the problem with randint() which includes the > endpoint; in Python this is usually not what you want. > > > I always find that comment amusing. While it is true that in slicing, > half-open ranges are more useful than closed ranges, but when it comes > to generating random numbers (say, simulating dice) I find randint much > more useful and intuitive. > > But I appreciate that some people think differently. Folks wanting to simulate die rolls should be using the random module rather than the secrets module anyway, so the "only offer secrets.randbelow()" approach Guido suggested in his last email makes sense to me. Regards, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message (by thread): [Python-Dev] PEP 506 secrets module
- Next message (by thread): [Python-Dev] PEP 506 secrets module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list