summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2021-01-02 20:09:56 (GMT)
committerGitHub <noreply@github.com>2021-01-02 20:09:56 (GMT)
commit8f8de7380cd7fee4972a10240ad2b0fdc332b14d (patch)
treeaf264620777c879b3420836e3afe546385c4d3fb /Lib/random.py
parent768fa145cfec2a0599802b74fc31d2bc2812ed96 (diff)
downloadcpython-8f8de7380cd7fee4972a10240ad2b0fdc332b14d.zip
cpython-8f8de7380cd7fee4972a10240ad2b0fdc332b14d.tar.gz
cpython-8f8de7380cd7fee4972a10240ad2b0fdc332b14d.tar.bz2
No need to test "istep==1" twice. (GH-24064)
Diffstat (limited to 'Lib/random.py')
-rw-r--r--Lib/random.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 97495f0..4142e2e 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -351,9 +351,9 @@ class Random(_random.Random):
DeprecationWarning, 2)
raise ValueError("non-integer step for randrange()")
width = istop - istart
- if istep == 1 and width > 0:
- return istart + self._randbelow(width)
if istep == 1:
+ if width > 0:
+ return istart + self._randbelow(width)
raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
# Non-unit step argument supplied.
@@ -363,10 +363,8 @@ class Random(_random.Random):
n = (width + istep + 1) // istep
else:
raise ValueError("zero step for randrange()")
-
if n <= 0:
raise ValueError("empty range for randrange()")
-
return istart + istep * self._randbelow(n)
def randint(self, a, b):