[Python-bugs-list] [ python-Bugs-599294 ] randrange overflow

noreply@sourceforge.net noreply@sourceforge.net
Fri, 23 Aug 2002 08:43:07 -0700


Bugs item #599294, was opened at 2002-08-23 10:43
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=599294&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Vadim Suvorov (xxx-bad)
Assigned to: Nobody/Anonymous (nobody)
Summary: randrange overflow

Initial Comment:
random.randrange causes overflow if range size is 
bigger than maximum integer:

~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> randrange(-0x7fffffff, 0x7fffffff)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "...\Python22\lib\random.py", line 299, in 
randrange
    return istart + int(self.random() *
OverflowError: float too large to convert
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

versions: Python 2.2, 2.2.1

The suggested change is to include 'istart' before 
conversion to 'int', thus normalizing intermediate 
result:

return int(istart + self.random() * (istop - istart))

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=599294&group_id=5470