[Python-checkins] python/dist/src/Lib random.py,1.48,1.49
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
2003年6月18日 20:23:08 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv27526/Lib
Modified Files:
random.py
Log Message:
randrange(): 2.3 can no longer raises OverflowError on an int() call, so
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).
Index: random.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/random.py,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** random.py 13 Jun 2003 07:01:51 -0000 1.48
--- random.py 19 Jun 2003 03:23:06 -0000 1.49
***************
*** 149,162 ****
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)))
if step == 1:
raise ValueError, "empty range for randrange()"
--- 149,153 ----
raise ValueError, "non-integer stop for randrange()"
if step == 1 and istart < istop:
! return int(istart + self.random()*(istop - istart))
if step == 1:
raise ValueError, "empty range for randrange()"