mirror of
https://github.com/python/cpython.git
synced 2025-11-10 10:32:04 +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):
|
def randint(self, a, b):
|
||||||
"""Return random integer in range [a, b], including both end points.
|
"""Return random integer in range [a, b], including both end points.
|
||||||
"""
|
"""
|
||||||
|
a = _index(a)
|
||||||
return self.randrange(a, b+1)
|
b = _index(b)
|
||||||
|
if b < a:
|
||||||
|
raise ValueError(f"empty range in randint({a}, {b})")
|
||||||
|
return a + self._randbelow(b - a + 1)
|
||||||
|
|
||||||
|
|
||||||
## -------------------- sequence methods -------------------
|
## -------------------- sequence methods -------------------
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
10-20% performance improvement of :func:`random.randint`.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue