]> granicus.if.org Git - python/commitdiff
randrange(): 2.3 can no longer raises OverflowError on an int() call, so
authorTim Peters <tim.peters@gmail.com>
Thu, 19 Jun 2003 03:23:06 +0000 (03:23 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 19 Jun 2003 03:23:06 +0000 (03:23 +0000)
some of this code because useless, and (worse) could return a long
instead of int (in Zope that's important, because a long can't be used
as a key in an IOBTree or IIBTree).

Lib/random.py

index defddbede9850d5b859a92c0394e84ec7ac481b9..0937ba20dc010dc75e3e3dfb777d7ba490056633 100644 (file)
@@ -148,16 +148,7 @@ class Random(_random.Random):
         if istop != stop:
             raise ValueError, "non-integer stop for randrange()"
         if step == 1 and istart < istop:
-            try:
-                return istart + int(self.random()*(istop - istart))
-            except OverflowError:
-                # This can happen if istop-istart > sys.maxint + 1, and
-                # multiplying by random() doesn't reduce it to something
-                # <= sys.maxint.  We know that the overall result fits
-                # in an int, and can still do it correctly via math.floor().
-                # But that adds another function call, so for speed we
-                # avoided that whenever possible.
-                return int(istart + _floor(self.random()*(istop - istart)))
+            return int(istart + self.random()*(istop - istart))
         if step == 1:
             raise ValueError, "empty range for randrange()"