summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/random.py')
-rw-r--r--Lib/random.py37
1 files changed, 18 insertions, 19 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 7932ac7..7210f62 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -687,17 +687,16 @@ class WichmannHill(Random):
## -------------------- test program --------------------
-def _test_generator(n, funccall):
+def _test_generator(n, func, args):
import time
- print n, 'times', funccall
- code = compile(funccall, funccall, 'eval')
+ print n, 'times', func.__name__
total = 0.0
sqsum = 0.0
smallest = 1e10
largest = -1e10
t0 = time.time()
for i in range(n):
- x = eval(code)
+ x = func(*args)
total += x
sqsum = sqsum + x*x
smallest = min(x, smallest)
@@ -711,21 +710,21 @@ def _test_generator(n, funccall):
def _test(N=2000):
- _test_generator(N, 'random()')
- _test_generator(N, 'normalvariate(0.0, 1.0)')
- _test_generator(N, 'lognormvariate(0.0, 1.0)')
- _test_generator(N, 'vonmisesvariate(0.0, 1.0)')
- _test_generator(N, 'gammavariate(0.01, 1.0)')
- _test_generator(N, 'gammavariate(0.1, 1.0)')
- _test_generator(N, 'gammavariate(0.1, 2.0)')
- _test_generator(N, 'gammavariate(0.5, 1.0)')
- _test_generator(N, 'gammavariate(0.9, 1.0)')
- _test_generator(N, 'gammavariate(1.0, 1.0)')
- _test_generator(N, 'gammavariate(2.0, 1.0)')
- _test_generator(N, 'gammavariate(20.0, 1.0)')
- _test_generator(N, 'gammavariate(200.0, 1.0)')
- _test_generator(N, 'gauss(0.0, 1.0)')
- _test_generator(N, 'betavariate(3.0, 3.0)')
+ _test_generator(N, random, ())
+ _test_generator(N, normalvariate, (0.0, 1.0))
+ _test_generator(N, lognormvariate, (0.0, 1.0))
+ _test_generator(N, vonmisesvariate, (0.0, 1.0))
+ _test_generator(N, gammavariate, (0.01, 1.0))
+ _test_generator(N, gammavariate, (0.1, 1.0))
+ _test_generator(N, gammavariate, (0.1, 2.0))
+ _test_generator(N, gammavariate, (0.5, 1.0))
+ _test_generator(N, gammavariate, (0.9, 1.0))
+ _test_generator(N, gammavariate, (1.0, 1.0))
+ _test_generator(N, gammavariate, (2.0, 1.0))
+ _test_generator(N, gammavariate, (20.0, 1.0))
+ _test_generator(N, gammavariate, (200.0, 1.0))
+ _test_generator(N, gauss, (0.0, 1.0))
+ _test_generator(N, betavariate, (3.0, 3.0))
# Create one instance, seeded from current time, and export its methods
# as module-level functions. The functions share state across all uses