[Numpy-discussion] Behavior of np.random.uniform

Chris Barker chris.barker at noaa.gov
Tue Jan 19 12:51:54 EST 2016


On Tue, Jan 19, 2016 at 9:27 AM, Charles R Harris <charlesr.harris at gmail.com
> wrote:

> On Tue, Jan 19, 2016 at 9:23 AM, Chris Barker - NOAA Federal <
> chris.barker at noaa.gov> wrote:
>
>> What does the standard lib do for rand range? I see that randint Is
>> closed on both ends, so order doesn't matter, though if it raises for b<a,
>> then that's a precedent we could follow.
>>
>
> randint is not closed on the high end. The now deprecated random_integers
> is the function that does that.
>

I was referring to the stdlib randint:

In [*7*]: [random.randint(2,5) for i in range(10)]

Out[*7*]: [5, 5, 2, 4, 5, 5, 3, 5, 2, 2]
thinking that compatibility with that would be good -- but that ship has
sailed.

randrange is open on the high end, as range is, (duh!)

 [random.randrange(2,5) for i in range(10)]

Out[*9*]: [3, 3, 4, 3, 3, 2, 4, 2, 3, 3]
but you get an exception is low >=high:

In [*10*]: random.randrange(5,2)

ValueError: empty range for randrange() (5,2, -3)
I like the exception idea best -- but backward compatibility and all that.

-CHB



-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20160119/4db1c3d9/attachment.html>


More information about the NumPy-Discussion mailing list