Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python random randrange() Method

Python random randrange() Method

Python random Module Python random Module

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

Syntax

The syntax of 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 package

import

random

Return a number between 1 and 9

print

(

random

.

randrange

(

1

,

9

)

)

Output result:


8

Python random Module Python random Module