96
96
SG_MAGICCONST = 1.0 + _log (4.5 )
97
97
BPF = 53 # Number of bits in a float
98
98
RECIP_BPF = 2 ** - BPF
99
- _ONE = 1
100
99
101
100
102
101
class Random (_random .Random ):
@@ -289,7 +288,7 @@ def randbytes(self, n):
289
288
290
289
## -------------------- integer methods -------------------
291
290
292
- def randrange (self , start , stop = None , step = _ONE ):
291
+ def randrange (self , start , stop = None , step = 1 ):
293
292
"""Choose a random item from range(start, stop[, step]).
294
293
295
294
This fixes the problem with randint() which includes the
@@ -322,13 +321,6 @@ def randrange(self, start, stop=None, step=_ONE):
322
321
_warn ('non-integer stop for randrange()' ,
323
322
DeprecationWarning , 2 )
324
323
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.
332
324
try :
333
325
istep = _index (step )
334
326
except TypeError :
@@ -337,6 +329,13 @@ def randrange(self, start, stop=None, step=_ONE):
337
329
raise ValueError ("non-integer step for randrange()" )
338
330
_warn ('non-integer step for randrange()' ,
339
331
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.
340
339
if istep > 0 :
341
340
n = (width + istep - 1 ) // istep
342
341
elif istep < 0 :
0 commit comments