http://docs.python.org/library/random.html

Hi,
I suspect I've found a documentation error in the above mentioned link ( http://docs.python.org/library/random.html); regarding random.randint(a, b), the documentation says "Return a random integer N such that a <= N <= b", however when actually using the function, it does seem to be a <= N < b.
Running Python 2.6, the built-in help returns
Type: builtin_function_or_method Base Class: <type 'builtin_function_or_method'> String Form: <built-in method randint of mtrand.RandomState object at 0x01466 340> Namespace: Interactive Docstring: randint(low, high=None, size=None) Return random integers from `low` (inclusive) to `high` (exclusive). Return random integers from the "discrete uniform" distribution in the "half-open" interval [`low`, `high`). If `high` is None (the default), then results are from [0, `low`).
which kind of hints that it should be "<".
Best regards Kristoffer Lundgren

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Am 02.01.2011 01:43, schrieb Kristoffer Lundgren:
Hi,
I suspect I've found a documentation error in the above mentioned link (http://docs.python.org/library/random.html); regarding random.randint(a, b), the documentation says "Return a random integer N such that a <= N <= b", however when actually using the function, it does seem to be a <= N < b.
Running Python 2.6, the built-in help returns
Type: builtin_function_or_method Base Class: <type 'builtin_function_or_method'> String Form: <built-in method randint of mtrand.RandomState object at 0x01466 340> Namespace: Interactive Docstring: randint(low, high=None, size=None) Return random integers from `low` (inclusive) to `high` (exclusive). Return random integers from the "discrete uniform" distribution in the "half-open" interval [`low`, `high`). If `high` is None (the default), then results are from [0, `low`).
which kind of hints that it should be "<".
Hi,
it seems your randint is not Python's randint, but the randint from scipy's "mtrand" module, which indeed defines randint differently.
cheers, Georg

I suspect I've found a documentation error in the above mentioned link ( http://docs.python.org/library/random.html); regarding random.randint(a, b), the documentation says "Return a random integer N such that a <= N <= b", however when actually using the function, it does seem to be a <= N < b.
Running Python 2.6, the built-in help returns
Type: builtin_function_or_method Base Class: <type 'builtin_function_or_method'> String Form: <built-in method randint of mtrand.RandomState object at 0x01466 340> Namespace: Interactive Docstring: randint(low, high=None, size=None) Return random integers from `low` (inclusive) to `high` (exclusive). Return random integers from the "discrete uniform" distribution in the "half-open" interval [`low`, `high`). If `high` is None (the default), then results are from [0, `low`).
randint indeed includes both endpoints:
for i in range(10):
... print random.randint(0, 1) ... 1 1 1 1 0 0 1 0 0 0
Its help string agrees:
help(random.randint)
Help on method randint in module random:
randint(self, a, b) method of random.Random instance Return random integer in range [a, b], including both end points.
participants (3)
-
Eli Bendersky
-
Georg Brandl
-
Kristoffer Lundgren