[Numpy-discussion] numpy.random.randint() inconsistent with plain random.randint()

Christopher Kerr gingekerr at gmail.com
Tue Feb 26 05:10:30 EST 2008


Robert Kern wrote:

> On Mon, Feb 25, 2008 at 2:58 PM, Christopher Kerr <gingekerr at gmail.com>
> wrote:
>> I don't know if this is the right place to report bugs, but I couldn't
>> find
>>  anywhere else on the website...
>>
>>  random.randint(min,max) from python core returns an integer between min
>>  and max inclusive. The documentation on the website says that
>>  numpy.random.randint(min,max [,size]) does this too, but it in fact only
>>  ever returns numbers strictly less than the max, and gives an error if
>>  min is equal to max
> 
> The documentation on what website? It needs to be fixed.
> numpy.random.randint() is behaving correctly. numpy.random is not
> intended to replace the standard library's random module.
> 

It looks like I might have misread the documentation the first time round.
It still seems rather silly to have a function with the same name as one in
the core distribution but with different semantics, though. (On the other
hand, you could argue that randint() in the core distribution is
inconsistent with the general policy in Python of describing ranges as
half-open intervals.) 

Perhaps the easiest way to deal with this without breaking things add
something in BIG BOLD LETTERS to the API docs saying that
numpy.random.randint behaves differently to the core random.randint, so
that other newbies don't hit the same problems as me (i.e. my Monte Carlo
never touching one side of my array).




More information about the NumPy-Discussion mailing list