[Numpy-discussion] making "low" optional in numpy.randint

Alan Isaac alan.isaac at gmail.com
Wed Feb 17 11:40:05 EST 2016


Behavior of random integer generation:
Python randint    [a,b]
MATLAB randi      [a,b]
Mma RandomInteger [a,b]
haskell randomR   [a,b]
GAUSS rndi        [a,b]
Maple rand        [a,b]

In short, NumPy's `randint` is non-standard (and,
I would add, non-intuitive).  Presumably was due
due to relying on a float draw from [0,1) along
with the use of floor.

The divergence in behavior between the (later) Python
function of the same name is particularly unfortunate.

So I suggest further work on this function is
not called for, and use of `random_integers`
should be encouraged.  Probably NumPy's `randint`
should be deprecated.

If there is any playing with the interface,
I think Mma provides a pretty good model.  If I were
designing the interface, I would always require a
tuple argument (for the inclusive range), with possible
`None` values to imply datatype extreme values.
Proposed name (after `randint` deprecation): `randints`.

Cheers,
Alan Isaac






More information about the NumPy-Discussion mailing list