[Python-checkins] Compute v only when needed. (#95183)

rhettinger webhook-mailer at python.org
Sat Jul 23 19:07:22 EDT 2022


https://github.com/python/cpython/commit/a2fbc511985f77c16c0f4a6fc6d3da9ab81a86b7
commit: a2fbc511985f77c16c0f4a6fc6d3da9ab81a86b7
branch: main
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2022-07-23T18:07:17-05:00
summary:

Compute v only when needed. (#95183)

files:
M Lib/random.py

diff --git a/Lib/random.py b/Lib/random.py
index 00849bd7e732f..ef0034adce5e7 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -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)
@@ -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
 



More information about the Python-checkins mailing list