New submission from Jon FRANCO <jonani.fra...@hotmail.fr>:

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

----------
components: Library (Lib)
messages: 385152
nosy: jonfranco, rhettinger
priority: normal
severity: normal
status: open
title: random.Random.sample bug when counts is not None
type: behavior
versions: Python 3.10, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42944>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to