This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Brian Nenninger
Recipients Brian Nenninger
Date 2016-12-24.06:24:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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)
>>> 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/", line 29, in randbelow
    return _sysrand._randbelow(exclusive_upper_bound)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/", line 232, in _randbelow
    r = getrandbits(k)          # 0 <= r < 2**k
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/", 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)
Date User Action Args
2016-12-24 06:24:43Brian Nenningersetrecipients: + Brian Nenninger
2016-12-24 06:24:43Brian Nenningersetmessageid: <>
2016-12-24 06:24:43Brian Nenningerlinkissue29061 messages
2016-12-24 06:24:42Brian Nenningercreate