mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +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
|
@ -227,6 +227,14 @@ class TestBasicOps:
|
|||
with self.assertRaises(IndexError):
|
||||
choices([], cum_weights=[], k=5)
|
||||
|
||||
def test_choices_subnormal(self):
|
||||
# Subnormal weights would occassionally trigger an IndexError
|
||||
# in choices() when the value returned by random() was large
|
||||
# enough to make `random() * total` round up to the total.
|
||||
# See https://bugs.python.org/msg275594 for more detail.
|
||||
choices = self.gen.choices
|
||||
choices(population=[1, 2], weights=[1e-323, 1e-323], k=5000)
|
||||
|
||||
def test_gauss(self):
|
||||
# Ensure that the seed() method initializes all the hidden state. In
|
||||
# particular, through 2.2.1 it failed to reset a piece of state used
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue