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 jonfranco
Recipients jonfranco, rhettinger
Date 2021-01-16.22:58:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610837934.67.0.783808477389.issue42944@roundup.psfhosted.org>
In-reply-to
Content
Hello,

If I am reading right, random.Random.sample method has a bug if counts is not None.

Line 482 (of master):
"""
            selections = sample(range(total), k=k)
"""
this is calling the module function 'sample' and not the instance method.

IMO this line should be:
"""
            selections = self.sample(range(total), k=k)
"""

Python 3.9.1 (default, Dec 11 2020, 14:32:07) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from random import Random
>>> r = Random()
>>> r.seed('bug')
>>> r.sample(range(50), 5, counts=range(1,51))
[34, 39, 31, 42, 38]
>>> r.seed('bug')
>>> r.sample(range(50), 5, counts=range(1,51))
[39, 11, 3, 12, 29]  <====== this should be [34, 39, 31, 42, 38]
>>> r.seed('nobug')
>>> r.sample(range(50), 5)
[0, 30, 23, 17, 49]
>>> r.seed('nobug')
>>> r.sample(range(50), 5)
[0, 30, 23, 17, 49]

Regards,
Jon FRANCO
History
Date User Action Args
2021-01-16 22:58:54jonfrancosetrecipients: + jonfranco, rhettinger
2021-01-16 22:58:54jonfrancosetmessageid: <1610837934.67.0.783808477389.issue42944@roundup.psfhosted.org>
2021-01-16 22:58:54jonfrancolinkissue42944 messages
2021-01-16 22:58:54jonfrancocreate