numpy.random.randint() inconsistent with plain random.randint()

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 Python 2.4.4 (#1, Dec 20 2007, 08:43:49) [GCC 4.1.2 20070214 ( (gdc 0.24, using dmd 1.020)) (Gentoo 4.1.2 p1.0.2)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import random import numpy.random numpy.version.version '1.0.4' random.randint(3,3) 3 numpy.random.randint(3,3) Traceback (most recent call last): File "<stdin>", line 1, in ? File "mtrand.pyx", line 600, in mtrand.RandomState.randint ValueError: low >= high numpy.random.randint(1,3,(2,10)) array([[2, 1, 2, 1, 2, 1, 2, 1, 2, 1], [1, 2, 1, 2, 1, 1, 1, 2, 1, 2]])

On Mon, Feb 25, 2008 at 2:58 PM, Christopher Kerr <gingekerr@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. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco

Robert Kern wrote:
On Mon, Feb 25, 2008 at 2:58 PM, Christopher Kerr <gingekerr@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).
participants (2)
-
Christopher Kerr
-
Robert Kern