diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2018-06-27 08:08:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-27 08:08:31 (GMT) |
commit | ddf7171911e117aa7ad4b0f9ded4f0c3a4ca0fec (patch) | |
tree | d8fc61e6eabb4d83d9e5dbe9b7f34192b7760b79 /Lib/test/test_random.py | |
parent | 3c8043d8fac4c0d05c0ba9e4e555e2f3165f2fe0 (diff) | |
download | cpython-ddf7171911e117aa7ad4b0f9ded4f0c3a4ca0fec.zip cpython-ddf7171911e117aa7ad4b0f9ded4f0c3a4ca0fec.tar.gz cpython-ddf7171911e117aa7ad4b0f9ded4f0c3a4ca0fec.tar.bz2 |
bpo-24567: Random subnormal.diff (#7954)
Handle subnormal weights for choices()
Diffstat (limited to 'Lib/test/test_random.py')
-rw-r--r-- | Lib/test/test_random.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index e7ef68b..38fd8a9 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -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 |