diff options
author | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2018-08-29 21:05:37 +0200 |
---|---|---|
committer | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2018-08-29 21:05:37 +0200 |
commit | 3d44139af1b65ec71abafec939b5240d3821490b (patch) | |
tree | 5206b8a818456b3ec0c740cf14d25d8351c77c28 /modules/language/python/module/random.py | |
parent | 9bd339b34f09f5b582cb8b77a11841f5de9ab695 (diff) |
shutil.py
Diffstat (limited to 'modules/language/python/module/random.py')
-rw-r--r-- | modules/language/python/module/random.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/modules/language/python/module/random.py b/modules/language/python/module/random.py index 31783cc..4c24977 100644 --- a/modules/language/python/module/random.py +++ b/modules/language/python/module/random.py @@ -69,7 +69,7 @@ RECIP_BPF = 2**-BPF import _random -class Random(_random.Random): +class Random (_random.Random): """Random number generator base class used by bound module functions. Used to instantiate instances of Random to get generators that don't @@ -703,9 +703,9 @@ class SystemRandom(Random): ## -------------------- test program -------------------- -import time def _test_generator(n, func, args): + import time print(n, 'times', func.__name__) total = 0.0 sqsum = 0.0 @@ -727,9 +727,33 @@ def _test_generator(n, func, args): print('avg %g, stddev %g, min %g, max %g\n' % \ (avg, stddev, smallest, largest)) +def _test_generator0(n, func): + import time + print(n, 'times', func.__name__) + total = 0.0 + sqsum = 0.0 + smallest = 1e10 + largest = -1e10 + t0 = time.time() + for i in range(n): + x = func() + total += x + sqsum = sqsum + x*x + smallest = min(x, smallest) + largest = max(x, largest) + + t1 = time.time() + print(round(t1-t0, 3), 'sec,', end=' ') + avg = total/n + stddev = _sqrt(sqsum/n - avg*avg) + + print('avg %g, stddev %g, min %g, max %g\n' % \ + (avg, stddev, smallest, largest)) + def _test(N=2000): _test_generator(N, random, ()) + _test_generator0(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)) |