Skip to content

Commit 844765b

Browse files
authored
gh-131269: Minor optimization in random.py (#131270)
1 parent c83efa7 commit 844765b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Lib/random.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,10 @@ def __init_subclass__(cls, /, **kwargs):
245245
def _randbelow_with_getrandbits(self, n):
246246
"Return a random int in the range [0,n). Defined for n > 0."
247247

248-
getrandbits = self.getrandbits
249248
k = n.bit_length()
250-
r = getrandbits(k) # 0 <= r < 2**k
249+
r = self.getrandbits(k) # 0 <= r < 2**k
251250
while r >= n:
252-
r = getrandbits(k)
251+
r = self.getrandbits(k)
253252
return r
254253

255254
def _randbelow_without_getrandbits(self, n, maxsize=1<<BPF):

0 commit comments

Comments
 (0)