summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_random.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-10-29 23:57:09 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-10-29 23:57:09 (GMT)
commitba25f6149052aea017df5fa328867d090bb89d1c (patch)
treea85f1c3e775ef3b1255a021751cb25e943c072e6 /Lib/test/test_random.py
parent7ca671532cee6e8ed80dbd6e461f1de50ee93a3b (diff)
parent30d00e54dde47b11f5b338aaba17760b641e1705 (diff)
downloadcpython-ba25f6149052aea017df5fa328867d090bb89d1c.zip
cpython-ba25f6149052aea017df5fa328867d090bb89d1c.tar.gz
cpython-ba25f6149052aea017df5fa328867d090bb89d1c.tar.bz2
merge
Diffstat (limited to 'Lib/test/test_random.py')
-rw-r--r--Lib/test/test_random.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index d061829..77d92e8 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -625,6 +625,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: