random.randint()

The random.randint() function takes in two int values, and returns a pseudo-random integer within the defined range of int values.

Syntax

random.randint(start, end)

An alias for randrange(start, end(+1)).

Example 1

Use random.randint() to return a random number between 0 and 50:

Example 2

Use random.randint() to return a random number between -25 and 25:

Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn Python on Codecademy

Edit this page on GitHub

Contributors