summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-08-30 01:24:19 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-08-30 01:24:19 (GMT)
commit62297132215490e9cb406e1a21f03aff40d421cb (patch)
tree11480371f3bf9639914a29ddef392ae6065308d9 /Lib/random.py
parent4f01f89b8c35235acfc93bcc4f6fe1b2645c0295 (diff)
downloadcpython-62297132215490e9cb406e1a21f03aff40d421cb.zip
cpython-62297132215490e9cb406e1a21f03aff40d421cb.tar.gz
cpython-62297132215490e9cb406e1a21f03aff40d421cb.tar.bz2
Eliminate unnecessary eval() in tests
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