Skip to content

Commit bcba8f6

Browse files
committed
impl
1 parent c1b42db commit bcba8f6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Lib/random.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,11 @@ def randrange(self, start, stop=None, step=_ONE):
336336
def randint(self, a, b):
337337
"""Return random integer in range [a, b], including both end points.
338338
"""
339-
340-
return self.randrange(a, b+1)
339+
a = _index(a)
340+
b = _index(b)
341+
if b < a:
342+
raise ValueError(f"empty range in randint({a}, {b})")
343+
return a + self._randbelow(b - a + 1)
341344

342345

343346
## -------------------- sequence methods -------------------

0 commit comments

Comments
 (0)