[issue24567] random.choice IndexError due to double-rounding

Raymond Hettinger report at bugs.python.org
Wed Jun 27 03:07:38 EDT 2018


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

I concur with Tim.  Marking the original bug as "won't fix" for the reasons that he listed.

In a separate PR, I'll modify the last line random.choices() to be "return [population[bisect(cum_weights, random() * total, 0, hi)] for i in range(k)]".  That will make the function more robust (handling the exotic case with subnormal weights).

----------
resolution:  -> wont fix
stage: needs patch -> resolved
status: open -> closed

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


More information about the Python-bugs-list mailing list