summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/random.py')
-rw-r--r--Lib/random.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 1e0dcc8..1006908 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -383,7 +383,9 @@ class Random(_random.Random):
raise ValueError('The number of weights does not match the population')
bisect = _bisect.bisect
total = cum_weights[-1]
- return [population[bisect(cum_weights, random() * total)] for i in range(k)]
+ hi = len(cum_weights) - 1
+ return [population[bisect(cum_weights, random() * total, 0, hi)]
+ for i in range(k)]
## -------------------- real-valued distributions -------------------