[New-bugs-announce] [issue1704] possible bug in randint

Rich Marinaccio report at bugs.python.org
Fri Dec 28 04:58:45 CET 2007


New submission from Rich Marinaccio:

I have been using python for Civilization IV map scripting, and I 
believe I have found a small problem with the randint function. Once in 
a blue moon, randint(a,b) returns b + 1, rather than a >= N <= b. I 
have seen this behavior a few times. Here is the code I used to 
determine this.

randIndex = PWRand.randint(0,len(preshuffle)-1)#PWRand calls randint 
directly with these parameters
if randIndex < 0 or randIndex >= len(preshuffle):
    raise ValueError, " bad index shuffling plot list randIndex=%(r)d 
listLength=%(l)d, mapSize=%(s)d" % {"r":randIndex,"l":len
(preshuffle),"s":hm.mapWidth*hm.mapHeight}

#output is
ValueError:  bad index shuffling plot list randIndex=1453 
listLength=1453, mapSize=13824

according to the docs, the max randIndex should be listLength - 1

----------
components: None
messages: 59012
nosy: cephalo
severity: normal
status: open
title: possible bug in randint
type: behavior
versions: Python 2.5

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1704>
__________________________________


More information about the New-bugs-announce mailing list