diff options
Diffstat (limited to 'Lib/random.py')
-rw-r--r-- | Lib/random.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/Lib/random.py b/Lib/random.py index c275071..7d8d4f3 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -431,22 +431,20 @@ class Random(_random.Random): if kappa <= 1e-6: return TWOPI * random() - a = 1.0 + _sqrt(1.0 + 4.0 * kappa * kappa) - b = (a - _sqrt(2.0 * a))/(2.0 * kappa) - r = (1.0 + b * b)/(2.0 * b) + s = 0.5 / kappa + r = s + _sqrt(1.0 + s * s) while 1: u1 = random() - z = _cos(_pi * u1) - f = (1.0 + r * z)/(r + z) - c = kappa * (r - f) + d = z / (r + z) u2 = random() - - if u2 < c * (2.0 - c) or u2 <= c * _exp(1.0 - c): + if u2 < 1.0 - d * d or u2 <= (1.0 - d) * _exp(d): break + q = 1.0 / r + f = (q + z) / (1.0 + q * z) u3 = random() if u3 > 0.5: theta = (mu + _acos(f)) % TWOPI |