summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-06-27 09:37:17 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2018-06-27 09:37:17 (GMT)
commitacda5ea916f4233ab90ca7b4d28af735aa962af3 (patch)
tree57895fea1cec1dc288f95d9ecea0b692efd99742 /Lib/random.py
parent6abf8c171760209d95e8a1ff28c211ae541e29ce (diff)
downloadcpython-acda5ea916f4233ab90ca7b4d28af735aa962af3.zip
cpython-acda5ea916f4233ab90ca7b4d28af735aa962af3.tar.gz
cpython-acda5ea916f4233ab90ca7b4d28af735aa962af3.tar.bz2
bpo-24567: Random subnormal.diff (GH-7954) (GH-7956)
Handle subnormal weights for choices() (cherry picked from commit ddf7171911e117aa7ad4b0f9ded4f0c3a4ca0fec) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
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 7a2585e..61e8816 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -360,7 +360,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 -------------------