[issue47114] random.choice and random.choices have different distributions

Raymond Hettinger report at bugs.python.org
Thu Mar 24 22:56:22 EDT 2022


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

This was an intentional decision.  It is documented and tested.  The rationale is that is keeps choices() internally consistent so that choices with equal weights produces the same result as if no weights are specified.

For anyone who wants an alternative, it is trivial just call choice() in a list comprehension:

   [choice(seq) for i in range(k)]

Another thought is that choices() is more performant than calling choice() in a loop.  This matters because one of the principal use cases for choices() in bootstrapping where choices() can be called many times.

Lastly, we are strongly averse to changing the algorithms after they are published because it impacts reproducible research where people need to be able to recreate their random selections for a given seed.

----------
nosy: +rhettinger
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue47114>
_______________________________________


More information about the Python-bugs-list mailing list