| Store | Cart

Re: [Python-Dev] PEP 506 secrets module

From: Serhiy Storchaka <stor...@gmail.com>
Fri, 16 Oct 2015 21:29:56 +0300
On 16.10.15 19:26, Steven D'Aprano wrote:
> On Fri, Oct 16, 2015 at 06:35:14PM +0300, Serhiy Storchaka wrote:>> I suggest to add only randrange(). randint() is historical artefact, we>> shouldn't repeat this mistake in new module. The secrets module is not>> good way to generate dice rolls. In most other cases you need to>> generate integers in half-open interval [0; N).>>>> And randbelow() is absolute redundant. Random._randbelow() is>> implementation detail and I inclined to get rid of it (implementing>> randrange() in C instead).>> This was discussed on Python-Ideas, and there was little consensus there> either. (Looks like Tim Peters' prediction is coming true :-)>> Putting aside your inflammatory description of randint() as a "mistake",> if you are correct that in most cases people will need to generate> integers in the half-open interval [0...n) then we should keep> randbelow, since that is precisely what it does.

Andrew explained the history of the issue 
(http://permalink.gmane.org/gmane.comp.python.ideas/36437). randrange 
was added in 61464037da53 to address a problem with unpythonic randint.

> Personally, I have no sense of which of the three functions will be most> useful, but if you are right about the half-open [0...n) interval, then> randbelow seems to be the right API to offer. But I have seen people> argue in favour of randint, and others argue in favour of randrange.> Given that these are just thin wrappers or aliases to methods of> random.SystemRandom, I don't think there is any harm in providing all> three.

Yes, randbelow provides simpler API, but randrange is more familiar for 
Python users due to similarity to range and because it is the public API 
in the random module (unlike to randbelow).


_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Steven DAprano Oct 16, 2015 12:57 am
Chris Rebert Oct 16, 2015 05:33 am
Victor Stinner Oct 16, 2015 06:57 am
Steven DAprano Oct 16, 2015 10:04 am
Chris Angelico Oct 16, 2015 10:32 am
Nick Coghlan Oct 20, 2015 09:11 am
Victor Stinner Oct 20, 2015 09:33 am
Nick Coghlan Oct 20, 2015 09:56 am
Serhiy Storchaka Oct 16, 2015 03:35 pm
Steven DAprano Oct 16, 2015 04:26 pm
Serhiy Storchaka Oct 16, 2015 06:29 pm
Guido van Rossum Oct 16, 2015 06:33 pm
Steven DAprano Oct 17, 2015 09:50 am
Guido van Rossum Oct 17, 2015 07:51 pm
Random832 Oct 17, 2015 08:30 pm
Tim Peters Oct 17, 2015 09:13 pm
Guido van Rossum Oct 17, 2015 11:05 pm
Brett Cannon Jan 14, 2016 06:36 pm
Guido van Rossum Jan 14, 2016 06:47 pm
Messages in this thread