[issue37000] _randbelow_with_getrandbits function inefficient with powers of two

2019-05-21 Thread Mathis Hammel
Change by Mathis Hammel : -- keywords: +patch pull_requests: +13398 stage: -> patch review ___ Python tracker <https://bugs.python.org/issue37000> ___ ___ Py

[issue37000] _randbelow_with_getrandbits function inefficient with powers of two

2019-05-21 Thread Mathis Hammel
New submission from Mathis Hammel : In case _randbelow_with_getrandbits is called with a power of two as its argument (say 2^k), the function will consume k+1 random bits instead of k. Instead of never being rejected, the sampled number will be rejected on average once per call, causing a