Message377483
This is a known limitation and there isn't much we can do about it.
The root cause is that for performance reasons the len() function doesn't handle sizes larger than a C ssize_t:
>>> len(range(2**100))
Traceback (most recent call last):
...
OverflowError: Python int too large to convert to C ssize_t
For the same reason, you would also see the same error for random.choice():
>>> random.choice(range(2**100))
Traceback (most recent call last):
...
OverflowError: Python int too large to convert to C ssize_t
Given that we can't get the size of the population, there isn't much that choice() or choices() can do about the situation without special casing range objects and reconstructing what len() would have returned had it not been restricted. Given that this hasn't seemed to have ever been a problem in practice, I recommend just using randrange() in a loop. |
|
Date |
User |
Action |
Args |
2020-09-25 08:24:22 | rhettinger | set | recipients:
+ rhettinger, mark.dickinson, serhiy.storchaka, mathtester |
2020-09-25 08:24:21 | rhettinger | set | messageid: <1601022261.97.0.80618957414.issue41860@roundup.psfhosted.org> |
2020-09-25 08:24:21 | rhettinger | link | issue41860 messages |
2020-09-25 08:24:21 | rhettinger | create | |
|