[Python-Dev] PEP 506 secrets module
ncoghlan at gmail.com
Tue Oct 20 05:11:33 EDT 2015
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.
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev