On Wed, Feb 17, 2016 at 4:40 PM, Alan Isaac <alan.is...@gmail.com> wrote:
>
> 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.

No, never was. It is implemented so because Python uses semi-open integer
intervals by preference because it plays most nicely with 0-based indexing.
Not sure about all of those systems, but some at least are 1-based
indexing, so closed intervals do make sense.

The Python stdlib's random.randint() closed interval is considered a
mistake by python-dev leading to the implementation and preference for
random.randrange() instead.

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

Indeed, but unfortunately, this mistake dates way back to Numeric times,
and easing the migration to numpy was a priority in the heady days of numpy
1.0.

> 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.

Not while I'm here. Instead, `random_integers()` is discouraged and perhaps
might eventually be deprecated.

--
Robert Kern
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to