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

noreply@sourceforge.net noreply@sourceforge.net
Fri, 23 Aug 2002 09:44:51 -0700


Bugs item #599294, was opened at 2002-08-23 11: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: Closed
>Resolution: Duplicate
Priority: 5
Submitted By: Vadim Suvorov (xxx-bad)
>Assigned to: Tim Peters (tim_one)
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))

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

>Comment By: Tim Peters (tim_one)
Date: 2002-08-23 12:44

Message:
Logged In: YES 
user_id=31435

Closed as Duplicate; see bug report 594996.

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

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