[Numpy-discussion] Random int64 and float64 numbers

David Cournapeau david at ar.media.kyoto-u.ac.jp
Sun Nov 1 23:07:00 EST 2009


Sturla Molden wrote:
> Sturla Molden skrev:
>   
>> Robert Kern skrev:
>>   
>>     
>>> Then let me clarify: it was written to support integer ranges up to
>>> sys.maxint. Absolutely, it would be desirable to extend it.
>>>
>>>   
>>>     
>>>       
>> Actually it only supports integers up to sys.maxint-1, as 
>> random_integers call randint. random_integers includes the upper range, 
>> but randint excludes the upper range. Thus, this happens on line 1153 in 
>> mtrand.pyx:
>>
>> return self.randint(low, high+1, size)
>>
>> inclusive upper interval should call rk_interval
>>   
>>     
>
> I love this one:
>
> cdef long lo, hi, diff
> [...]
> diff = hi - lo - 1
>
> which silently overflows, and is the reason for this strange exception:
>
>  >>> np.random.random_integers(-2147483648,high=2147483646,size=10)
>
> Traceback (most recent call last):
>   File "<pyshell#68>", line 1, in <module>
>     np.random.random_integers(-2147483648,high=2147483646,size=10)
>   File "mtrand.pyx", line 950, in mtrand.RandomState.random_integers
>   File "mtrand.pyx", line 750, in mtrand.RandomState.randint
> ValueError: low >= high
>
> I'll call this a bug.
>   

Yep, I was bitten by it as well: http://projects.scipy.org/numpy/ticket/965

David



More information about the NumPy-Discussion mailing list