diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2022-07-24 19:21:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-24 19:21:29 (GMT) |
commit | eb9c8a8bea9128b31d4a604c4a1f27ec9b45f333 (patch) | |
tree | 10864dc175fcb75bad98e2a865563342056d57b8 /Lib/random.py | |
parent | 00474472944944b346d8409cfded84bb299f601a (diff) | |
download | cpython-eb9c8a8bea9128b31d4a604c4a1f27ec9b45f333.zip cpython-eb9c8a8bea9128b31d4a604c4a1f27ec9b45f333.tar.gz cpython-eb9c8a8bea9128b31d4a604c4a1f27ec9b45f333.tar.bz2 |
log2() is faster than log() (#95214)
Diffstat (limited to 'Lib/random.py')
-rw-r--r-- | Lib/random.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/random.py b/Lib/random.py index ef0034a..7662730 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -50,7 +50,7 @@ from warnings import warn as _warn 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 tau as TWOPI, floor as _floor, isfinite as _isfinite -from math import lgamma as _lgamma, fabs as _fabs +from math import lgamma as _lgamma, fabs as _fabs, log2 as _log2 from os import urandom as _urandom from _collections_abc import Sequence as _Sequence from operator import index as _index @@ -764,11 +764,11 @@ class Random(_random.Random): # BG: Geometric method by Devroye with running time of O(np). # https://dl.acm.org/doi/pdf/10.1145/42372.42381 x = y = 0 - c = _log(1.0 - p) + c = _log2(1.0 - p) if not c: return x while True: - y += _floor(_log(random()) / c) + 1 + y += _floor(_log2(random()) / c) + 1 if y > n: return x x += 1 |