mirror of
https://github.com/python/cpython.git
synced 2025-10-20 00:13:47 +00:00
gh-131435: random.randint optimization (gh-131436)
This commit is contained in:
parent
ce79274e9f
commit
c83efa7a66
2 changed files with 6 additions and 2 deletions
|
@ -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 -------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue