Author Brian Nenninger
Recipients Brian Nenninger
Date 2016-12-24.06:24:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1482560683.53.0.415654381831.issue29061@psf.upfronthosting.co.za>
In-reply-to
Content
secrets.randbelow(-1) causes the interpreter to hang. It should presumably raise an exception like secrets.randbelow(0) does. This is on Mac OS X 10.11.6, shell transcript below.

=========================================================

$ python3
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import secrets
>>> secrets.randbelow(1)
0
>>> secrets.randbelow(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/secrets.py", line 29, in randbelow
    return _sysrand._randbelow(exclusive_upper_bound)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/random.py", line 232, in _randbelow
    r = getrandbits(k)          # 0 <= r < 2**k
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/random.py", line 678, in getrandbits
    raise ValueError('number of bits must be greater than zero')
ValueError: number of bits must be greater than zero
>>> secrets.randbelow(-1)

(hangs using 100% CPU until aborted)
History
Date User Action Args
2016-12-24 06:24:43Brian Nenningersetrecipients: + Brian Nenninger
2016-12-24 06:24:43Brian Nenningersetmessageid: <1482560683.53.0.415654381831.issue29061@psf.upfronthosting.co.za>
2016-12-24 06:24:43Brian Nenningerlinkissue29061 messages
2016-12-24 06:24:42Brian Nenningercreate