This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients mark.dickinson, mathtester, rhettinger, serhiy.storchaka
Date 2020-09-25.08:24:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1601022261.97.0.80618957414.issue41860@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-09-25 08:24:22rhettingersetrecipients: + rhettinger, mark.dickinson, serhiy.storchaka, mathtester
2020-09-25 08:24:21rhettingersetmessageid: <1601022261.97.0.80618957414.issue41860@roundup.psfhosted.org>
2020-09-25 08:24:21rhettingerlinkissue41860 messages
2020-09-25 08:24:21rhettingercreate