Message385152
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 |
|
Date |
User |
Action |
Args |
2021-01-16 22:58:54 | jonfranco | set | recipients:
+ jonfranco, rhettinger |
2021-01-16 22:58:54 | jonfranco | set | messageid: <1610837934.67.0.783808477389.issue42944@roundup.psfhosted.org> |
2021-01-16 22:58:54 | jonfranco | link | issue42944 messages |
2021-01-16 22:58:54 | jonfranco | create | |
|