gh-131435: random.randint optimization (gh-131436)

This commit is contained in:
dgpb 2025-03-21 00:07:28 +02:00 committed by GitHub
parent ce79274e9f
commit c83efa7a66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View file

@ -336,8 +336,11 @@ def randrange(self, start, stop=None, step=_ONE):
def randint(self, a, b):
"""Return random integer in range [a, b], including both end points.
"""
return self.randrange(a, b+1)
a = _index(a)
b = _index(b)
if b < a:
raise ValueError(f"empty range in randint({a}, {b})")
return a + self._randbelow(b - a + 1)
## -------------------- sequence methods -------------------