https://github.com/python/cpython/commit/844765b20f993e69fd6b7b70341f636fb84b473d
commit: 844765b20f993e69fd6b7b70341f636fb84b473d
branch: main
author: Sam Gross <colesb...@gmail.com>
committer: rhettinger <rhettin...@users.noreply.github.com>
date: 2025-03-20T17:10:33-05:00
summary:

gh-131269: Minor optimization in random.py (#131270)

files:
M Lib/random.py

diff --git a/Lib/random.py b/Lib/random.py
index d6f5337d40f6ba..5e5d0c4c694a1c 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -245,11 +245,10 @@ def __init_subclass__(cls, /, **kwargs):
     def _randbelow_with_getrandbits(self, n):
         "Return a random int in the range [0,n).  Defined for n > 0."
 
-        getrandbits = self.getrandbits
         k = n.bit_length()
-        r = getrandbits(k)  # 0 <= r < 2**k
+        r = self.getrandbits(k)  # 0 <= r < 2**k
         while r >= n:
-            r = getrandbits(k)
+            r = self.getrandbits(k)
         return r
 
     def _randbelow_without_getrandbits(self, n, maxsize=1<<BPF):

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to