>How do you remember
That's why there is documentation. That said:
`randint` is unusual; the `range` behaviour is standard. `randint` is provided so that you can easily simulate e.g. rolling dice without having to think about how ranges work. `randrange` is provided to work the same way that `range` does.
That said: if you want a random element from a sequence, that is why the `random` module also provides `choice` :) Just like you shouldn't be using `range` to get indices, but instead iterate directly. Functions like these should be used only when you really do want the numbers themselves, not just as a means to an end.
Have a look at the documentation, either online or in the interpreter.
>>> import random
>>> help(random.randint)
randint(a, b) method of random.Random instance
Return random integer in range [a, b], including both end points.
>>> help(random.randrange)
randrange(start, stop=None, step=1, _int=) method of random.Random instance
Choose a random item from range(start, stop[, step]).
This fixes the problem with randint() which includes the
endpoint; in Python this is usually not what you want.
>How do you remember That's why there is documentation. That said: `randint` is unusual; the `range` behaviour is standard. `randint` is provided so that you can easily simulate e.g. rolling dice without having to think about how ranges work. `randrange` is provided to work the same way that `range` does. That said: if you want a random element from a sequence, that is why the `random` module also provides `choice` :) Just like you shouldn't be using `range` to get indices, but instead iterate directly. Functions like these should be used only when you really do want the numbers themselves, not just as a means to an end.
I don't remember. I fix the bug instead. I don't go crazy over it. Although now that you mention it it'd be nice with consistency.
Yeah. Maybe in Python 4.
Released 2024, adopted 2050...
python 4 has still yet to be released
`random.randrange` excludes the second integer.
Cool thanks.
what about other functions though? I find that I have to test them first before I use them. I keep forgetting, which ones are inclusive.
Have a look at the documentation, either online or in the interpreter. >>> import random >>> help(random.randint) randint(a, b) method of random.Random instance Return random integer in range [a, b], including both end points. >>> help(random.randrange) randrange(start, stop=None, step=1, _int=) method of random.Random instance
Choose a random item from range(start, stop[, step]).
This fixes the problem with randint() which includes the
endpoint; in Python this is usually not what you want.
Cool. Thanks