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 Dennis Sweeney, mark.dickinson, rhettinger
Date 2021-05-09.17:58:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1620583099.08.0.799725604152.issue44080@roundup.psfhosted.org>
In-reply-to
Content
This is known and an intentional design decision.  It isn't just a speed issue.  Because the weights can be floats, we have floats involved at the outset and some round-off is unavoidable.  To keep the method internally consistent, the same technique is used even when the weights aren't specified:

    >>> from random import choices, seed
    >>> seed(8675309**3)
    >>> s = choices('abcdefg', k=20)
    >>> seed(8675309**3)
    >>> t = choices('abcdefg', [0.7] * 7, k=20)
    >>> s == t
    True

FWIW, this is documented: 
"""
For a given seed, the choices() function with equal weighting typically produces a different sequence than repeated calls to choice(). The algorithm used by choices() uses floating point arithmetic for internal consistency and speed. The algorithm used by choice() defaults to integer arithmetic with repeated selections to avoid small biases from round-off error.
"""
History
Date User Action Args
2021-05-09 17:58:19rhettingersetrecipients: + rhettinger, mark.dickinson, Dennis Sweeney
2021-05-09 17:58:19rhettingersetmessageid: <1620583099.08.0.799725604152.issue44080@roundup.psfhosted.org>
2021-05-09 17:58:19rhettingerlinkissue44080 messages
2021-05-09 17:58:17rhettingercreate