Python random randrange() Method
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:
- start -- optional, an integer specifying the start value, defaults to 0.
- stop -- required, an integer specifying the end value.
- step -- optional, an integer specifying the step, defaults to 1.
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
(
random
.
randrange
(
1
,
9
)
)
Output result:
8
Python random Module