Brendan Donegan added the comment: Ok, here it is. My first code patch in Python.
Basically the existing code was depending on bit_length to DTRT and raise a ValueError, but negative numbers have a positive bit length. Then when it hits: 234 while r >= n: 235 r = getrandbits(k) It just spins on that as r is always going to be greater than a negative number. I tried not to be too clever so just put a guard early in the function. This has the added advantage of giving us a clearer error message. ---------- keywords: +patch Added file: http://bugs.python.org/file46021/issue_29061_randbelow.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29061> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com