summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_random.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-10-30 00:43:02 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-10-30 00:43:02 (GMT)
commitfdf6716ea98440a64fad85934e1f23de188cd49c (patch)
tree063918b7439e0a938b195f93ab308c0fc7cde8ec /Lib/test/test_random.py
parentba25f6149052aea017df5fa328867d090bb89d1c (diff)
parent77d574d4aeae4b7b9b976a68b367783a0932b6c8 (diff)
downloadcpython-fdf6716ea98440a64fad85934e1f23de188cd49c.zip
cpython-fdf6716ea98440a64fad85934e1f23de188cd49c.tar.gz
cpython-fdf6716ea98440a64fad85934e1f23de188cd49c.tar.bz2
merge
Diffstat (limited to 'Lib/test/test_random.py')
-rw-r--r--Lib/test/test_random.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index 77d92e8..f86077c 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -641,6 +641,23 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase):
c = self.gen.choices(range(n), cum_weights=range(1, n+1), k=10000)
self.assertEqual(a, c)
+ # Amerian Roulette
+ population = ['Red', 'Black', 'Green']
+ weights = [18, 18, 2]
+ cum_weights = [18, 36, 38]
+ expanded_population = ['Red'] * 18 + ['Black'] * 18 + ['Green'] * 2
+
+ self.gen.seed(9035768)
+ a = self.gen.choices(expanded_population, k=10000)
+
+ self.gen.seed(9035768)
+ b = self.gen.choices(population, weights, k=10000)
+ self.assertEqual(a, b)
+
+ self.gen.seed(9035768)
+ c = self.gen.choices(population, cum_weights=cum_weights, 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: