Skip to content

Commit fcd6549

Browse files
Remove _ONE.
1 parent fb9382e commit fcd6549

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Lib/random.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
SG_MAGICCONST = 1.0 + _log(4.5)
9797
BPF = 53 # Number of bits in a float
9898
RECIP_BPF = 2 ** -BPF
99-
_ONE = 1
10099

101100

102101
class Random(_random.Random):
@@ -289,7 +288,7 @@ def randbytes(self, n):
289288

290289
## -------------------- integer methods -------------------
291290

292-
def randrange(self, start, stop=None, step=_ONE):
291+
def randrange(self, start, stop=None, step=1):
293292
"""Choose a random item from range(start, stop[, step]).
294293
295294
This fixes the problem with randint() which includes the
@@ -322,13 +321,6 @@ def randrange(self, start, stop=None, step=_ONE):
322321
_warn('non-integer stop for randrange()',
323322
DeprecationWarning, 2)
324323
width = istop - istart
325-
# Fast path.
326-
if step is _ONE:
327-
if width > 0:
328-
return istart + self._randbelow(width)
329-
raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
330-
331-
# Non-unit step argument supplied.
332324
try:
333325
istep = _index(step)
334326
except TypeError:
@@ -337,6 +329,13 @@ def randrange(self, start, stop=None, step=_ONE):
337329
raise ValueError("non-integer step for randrange()")
338330
_warn('non-integer step for randrange()',
339331
DeprecationWarning, 2)
332+
# Fast path.
333+
if istep == 1:
334+
if width > 0:
335+
return istart + self._randbelow(width)
336+
raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
337+
338+
# Non-unit step argument supplied.
340339
if istep > 0:
341340
n = (width + istep - 1) // istep
342341
elif istep < 0:

0 commit comments

Comments
 (0)