diff --git a/Lib/random.py b/Lib/random.py --- a/Lib/random.py +++ b/Lib/random.py @@ -39,7 +39,7 @@ from warnings import warn as _warn from types import MethodType as _MethodType, BuiltinMethodType as _BuiltinMethodType from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil -from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin +from math import acos as _acos, cos as _cos, sin as _sin from os import urandom as _urandom from _collections_abc import Set as _Set, Sequence as _Sequence from hashlib import sha512 as _sha512 @@ -51,12 +51,12 @@ "getstate","setstate", "getrandbits", "SystemRandom"] -NV_MAGICCONST = 4 * _exp(-0.5)/_sqrt(2.0) -TWOPI = 2.0*_pi +NV_MAGICCONST = 4 * _exp(-0.5) / (2.0) ** 0.5 +TWOPI = 2.0 * _pi LOG4 = _log(4.0) SG_MAGICCONST = 1.0 + _log(4.5) BPF = 53 # Number of bits in a float -RECIP_BPF = 2**-BPF +RECIP_BPF = 2 ** -BPF # Translated by Guido van Rossum from C source provided by @@ -448,7 +448,7 @@ return TWOPI * random() s = 0.5 / kappa - r = s + _sqrt(1.0 + s * s) + r = s + (1.0 + s * s) ** 0.5 while 1: u1 = random() @@ -498,7 +498,7 @@ # variables with non-integral shape parameters", # Applied Statistics, (1977), 26, No. 1, p71-74 - ainv = _sqrt(2.0 * alpha - 1.0) + ainv = (2.0 * alpha - 1.0) ** 0.5 bbb = alpha - LOG4 ccc = alpha + ainv @@ -576,7 +576,7 @@ self.gauss_next = None if z is None: x2pi = random() * TWOPI - g2rad = _sqrt(-2.0 * _log(1.0 - random())) + g2rad = (-2.0 * _log(1.0 - random())) ** 0.5 z = _cos(x2pi) * g2rad self.gauss_next = _sin(x2pi) * g2rad @@ -686,7 +686,7 @@ t1 = time.time() print(round(t1-t0, 3), 'sec,', end=' ') avg = total/n - stddev = _sqrt(sqsum/n - avg*avg) + stddev = (sqsum/n - avg*avg) ** 0.5 print('avg %g, stddev %g, min %g, max %g\n' % \ (avg, stddev, smallest, largest))