From 30d00e54dde47b11f5b338aaba17760b641e1705 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 29 Oct 2016 16:55:36 -0700 Subject: Issue #18844: Make the various ways for specifing weights produce the same results. --- Lib/test/test_random.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Lib/test/test_random.py') diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index 4d5a8749c7..dd2715288a 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -629,6 +629,22 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase): self.assertTrue(stop < x <= start) self.assertEqual((x+stop)%step, 0) + def test_choices_algorithms(self): + # The various ways of specifing weights should produce the same results + choices = self.gen.choices + n = 13132817 + + self.gen.seed(8675309) + a = self.gen.choices(range(n), k=10000) + + self.gen.seed(8675309) + b = self.gen.choices(range(n), [1]*n, k=10000) + self.assertEqual(a, b) + + self.gen.seed(8675309) + c = self.gen.choices(range(n), cum_weights=range(1, n+1), k=10000) + self.assertEqual(a, c) + def gamma(z, sqrt2pi=(2.0*pi)**0.5): # Reflection to right half of complex plane if z < 0.5: -- cgit v1.2.1