Easy Tutorial
❮ Python Mongodb Sort Python Sum Dictionary ❯

Python random randrange() Method

Python random Module

The random.randrange() method in Python returns a random number within the specified range.

Syntax

The syntax for the random.randrange() method is as follows:

random.randrange(start, stop, step)

Parameter Description:

Return Value

Returns an integer within the specified range.

Example

The following example returns a number between 1 and 9 (greater than or equal to 1, less than 9):

Example

# Import the random module
import random

# Return a number between 1 and 9
print(random.randrange(1, 9))

Output result:

8

Python random Module

❮ Python Mongodb Sort Python Sum Dictionary ❯