Message343094
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 computational overhead in addition to wasting k+2 bits on average.
This is due to taking n.bit_size() instead of (n-1).bit_size() for the size of the random candidates. Using n instead of n-1 is apparently deliberate in order to save the case where n = 1, but this could be avoided by directly returning 0 if n == 1. |
|
Date |
User |
Action |
Args |
2019-05-21 20:50:16 | Mathis Hammel | set | recipients:
+ Mathis Hammel, rhettinger, mark.dickinson |
2019-05-21 20:50:16 | Mathis Hammel | set | messageid: <1558471816.52.0.343821776026.issue37000@roundup.psfhosted.org> |
2019-05-21 20:50:16 | Mathis Hammel | link | issue37000 messages |
2019-05-21 20:50:16 | Mathis Hammel | create | |
|