Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cpython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sip
Cpython
Commits
eb9c8a8b
Unverified
Commit
eb9c8a8b
authored
Jul 24, 2022
by
Raymond Hettinger
Committed by
GitHub
Jul 24, 2022
Browse files
Options
Downloads
Patches
Plain Diff
log2() is faster than log() (#95214)
parent
00474472
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Lib/random.py
+3
-3
3 additions, 3 deletions
Lib/random.py
with
3 additions
and
3 deletions
Lib/random.py
+
3
−
3
View file @
eb9c8a8b
...
@@ -50,7 +50,7 @@
...
@@ -50,7 +50,7 @@
from
math
import
log
as
_log
,
exp
as
_exp
,
pi
as
_pi
,
e
as
_e
,
ceil
as
_ceil
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
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
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
os
import
urandom
as
_urandom
from
_collections_abc
import
Sequence
as
_Sequence
from
_collections_abc
import
Sequence
as
_Sequence
from
operator
import
index
as
_index
from
operator
import
index
as
_index
...
@@ -764,11 +764,11 @@ def binomialvariate(self, n=1, p=0.5):
...
@@ -764,11 +764,11 @@ def binomialvariate(self, n=1, p=0.5):
# BG: Geometric method by Devroye with running time of O(np).
# BG: Geometric method by Devroye with running time of O(np).
# https://dl.acm.org/doi/pdf/10.1145/42372.42381
# https://dl.acm.org/doi/pdf/10.1145/42372.42381
x
=
y
=
0
x
=
y
=
0
c
=
_log
(
1.0
-
p
)
c
=
_log
2
(
1.0
-
p
)
if
not
c
:
if
not
c
:
return
x
return
x
while
True
:
while
True
:
y
+=
_floor
(
_log
(
random
())
/
c
)
+
1
y
+=
_floor
(
_log
2
(
random
())
/
c
)
+
1
if
y
>
n
:
if
y
>
n
:
return
x
return
x
x
+=
1
x
+=
1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment