How to use randint in python

❮ Random Methods


Example

Return a number between 3 and 9 (both included):

import random

print(random.randint(3, 9))

Try it Yourself »


Definition and Usage

The randint() method returns an integer number selected element from the specified range.

Note: This method is an alias for randrange(start, stop+1).


Syntax

random.randint(start, stop)

Parameter Values

ParameterDescription
start Required. An integer specifying at which position to start.
stop Required. An integer specifying at which position to end.

❮ Random Methods


How do I run Randint in Python?

Use randint() Generate random integer Use a random. randint() function to get a random integer number from the inclusive range. For example, random. randint(0, 10) will return a random number from [0, 1, 2, 3, 4, 5, 6, 7, 8 ,9, 10].

How does Randint function work in Python?

The randint() method Syntax Basically, the randint() method in Python returns a random integer value between the two lower and higher limits (including both limits) provided as two parameters. It should be noted that this method is only capable of generating integer-type random value.

What is the use of random Randint in Python?

Python Random randint() Method The randint() method returns an integer number selected element from the specified range. Note: This method is an alias for randrange(start, stop+1) .

What is Randint library in Python?

randint() function is used to generate the random integers between the two given numbers passed as parameters. Randint is an in-built function of random library in python. So we have to import the random library at the start of our code to generate random numbers.