[New-bugs-announce] [issue31689] random.choices does not work with negative weights
Allen Riddell
report at bugs.python.org
Wed Oct 4 08:53:19 EDT 2017
New submission from Allen Riddell <abr at ariddell.org>:
Code to reproduce problem:
population = list(range(10))
weights = list(-1 * w for w in range(10))
[random.choices(population, weights) for _ in range(1000)]
will raise IndexError:
358 bisect = _bisect.bisect
359 total = cum_weights[-1]
--> 360 return [population[bisect(cum_weights, random() * total)] for i in range(k)]
361
362 ## -------------------- real-valued distributions -------------------
IndexError: list index out of range
----------
components: Library (Lib)
messages: 303683
nosy: ariddell
priority: normal
severity: normal
status: open
title: random.choices does not work with negative weights
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31689>
_______________________________________
More information about the New-bugs-announce
mailing list