Skip to content

Commit

Permalink
Compute v only when needed. (#95183)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettinger authored Jul 23, 2022
1 parent 23f6944 commit a2fbc51
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,6 @@ def binomialvariate(self, n=1, p=0.5):
while True:

u = random()
v = random()
u -= 0.5
us = 0.5 - _fabs(u)
k = _floor((2.0 * a / us + b) * u + c)
Expand All @@ -796,6 +795,7 @@ def binomialvariate(self, n=1, p=0.5):

# The early-out "squeeze" test substantially reduces
# the number of acceptance condition evaluations.
v = random()
if us >= 0.07 and v <= vr:
return k

Expand Down

0 comments on commit a2fbc51

Please sign in to comment.