mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
bpo-24567: Random subnormal.diff (#7954)
Handle subnormal weights for choices()
This commit is contained in:
parent
3c8043d8fa
commit
ddf7171911
3 changed files with 13 additions and 1 deletions
|
@ -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 -------------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue