[PYTHON] Watch out for randint

A note I was addicted to with Python's randint. There are random.randint and numpy.random.randint as functions that return random integers within a certain interval, but these are actually different specifications.

Take a look at the documentation. First from random.randint

randint(self, a, b) method of random.Random instance Return random integer in range [a, b], including both end points.

Then numpy.random.randint

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

In other words, random.randint (a, b) may return an integer from a to b (including b), and numpy.random.randint (a, b) may return an integer from a to b-1. There is a possibility that it will come back.

What the hell is that! confusing!

I think the latter is the more natural specification. For example, range (1,5) returns [1,2,3,4].

Then, Happy Halloween and Happy Hacking!

Recommended Posts

Watch out for randint
2015-03-25 python> Multi-line comment> Watch out for indent
Watch out for the return value of __len__
Watch out for global variables outside of lambda_handler (datetime)
Things to watch out for when migrating with Django
Things to watch out for when using default arguments in Python
Things to watch out for when naming dynamic routing in nuxt.js
Things to watch out for when creating a Python environment on a Mac