diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2018-06-27 01:08:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-27 01:08:31 -0700 |
commit | ddf7171911e117aa7ad4b0f9ded4f0c3a4ca0fec (patch) | |
tree | d8fc61e6eabb4d83d9e5dbe9b7f34192b7760b79 /Lib/random.py | |
parent | 3c8043d8fac4c0d05c0ba9e4e555e2f3165f2fe0 (diff) | |
download | cpython-git-ddf7171911e117aa7ad4b0f9ded4f0c3a4ca0fec.tar.gz |
bpo-24567: Random subnormal.diff (#7954)
Handle subnormal weights for choices()
Diffstat (limited to 'Lib/random.py')
-rw-r--r-- | Lib/random.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/random.py b/Lib/random.py index 1e0dcc87ed..1006908491 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 ------------------- |