[docs] Mistake in random.py documentation?

Tyler Arbour tyler.arbour at berkeley.edu
Fri Jan 22 10:27:23 EST 2016


Hi,

I’m reporting what I think might be a mistake for the documentation of random.py. Sorry that I am short on time and have never reported a bug (new user), so apologies if the Tracker is the preferred way.

Reading the stuff below, it is unclear whether randrange(0, 5) includes 5 in the set it’s choosing integers from. Furthermore, randint(0, 5) explicitly says “alias for randrange(a, b+1) which to me suggests randint includes the “stop” integer and randrange does not.

I tested both (see screenshot) and see that neither consider 5 in the set. This seems wrong to me. I’m curious to know though, so I’d love a response if at all possible.

Thanks!
Tyler


##########################################
(From the docs:)
Functions for integers:

random.randrange(stop) <https://docs.python.org/3/library/random.html?highlight=random#random.randrange>
random.randrange(start, stop[, step])
Return a randomly selected element from range(start, stop, step). This is equivalent to choice(range(start, stop, step)), but doesn’t actually build a range object.

The positional argument pattern matches that of range() <https://docs.python.org/3/library/stdtypes.html#range>. Keyword arguments should not be used because the function may use them in unexpected ways.

Changed in version 3.2: randrange() <https://docs.python.org/3/library/random.html?highlight=random#random.randrange> is more sophisticated about producing equally distributed values. Formerly it used a style like int(random()*n) which could produce slightly uneven distributions.

random.randint(a, b) <https://docs.python.org/3/library/random.html?highlight=random#random.randint>
Return a random integer N such that a <= N <= b. Alias for randrange(a, b+1).


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20160122/4a77896e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2016-01-22 at 7.17.33 AM.png
Type: image/png
Size: 95439 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/docs/attachments/20160122/4a77896e/attachment-0001.png>


More information about the docs mailing list