Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:
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. ---------- resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41860> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com