diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-11-25 21:12:43 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-11-25 21:12:43 (GMT) |
commit | dc47a89ff19b932c1c794422a5223847b4e64f0e (patch) | |
tree | 9aa0fb912a1b0b4c866d518c09bdd9a2b3537ef7 /Lib | |
parent | 652e1917c6f2bcdccb784d9d37950c381948a77c (diff) | |
download | cpython-dc47a89ff19b932c1c794422a5223847b4e64f0e.zip cpython-dc47a89ff19b932c1c794422a5223847b4e64f0e.tar.gz cpython-dc47a89ff19b932c1c794422a5223847b4e64f0e.tar.bz2 |
SF patch 483059: Avoid use of eval() in random.py, from Finn Bock.
_verify(): Pass in the values of globals insted of eval()ing their
names. The use of eval() was obscure and unnecessary, and the patch
claimed random.py couldn't be used in Jython applets because of it.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/random.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/Lib/random.py b/Lib/random.py index 1fe0b82..4259973 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -82,24 +82,23 @@ __all__ = ["Random","seed","random","uniform","randint","choice", "stdgamma","gauss","betavariate","paretovariate","weibullvariate", "getstate","setstate","jumpahead","whseed"] -def _verify(name, expected): - computed = eval(name) +def _verify(name, computed, expected): if abs(computed - expected) > 1e-7: raise ValueError( "computed value for %s deviates too much " "(computed %g, expected %g)" % (name, computed, expected)) NV_MAGICCONST = 4 * _exp(-0.5)/_sqrt(2.0) -_verify('NV_MAGICCONST', 1.71552776992141) +_verify('NV_MAGICCONST', NV_MAGICCONST, 1.71552776992141) TWOPI = 2.0*_pi -_verify('TWOPI', 6.28318530718) +_verify('TWOPI', TWOPI, 6.28318530718) LOG4 = _log(4.0) -_verify('LOG4', 1.38629436111989) +_verify('LOG4', LOG4, 1.38629436111989) SG_MAGICCONST = 1.0 + _log(4.5) -_verify('SG_MAGICCONST', 2.50407739677627) +_verify('SG_MAGICCONST', SG_MAGICCONST, 2.50407739677627) del _verify |