New submission from Allen Riddell <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue31689>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com