About Lesson
randrange() Method
The randrange() method returns a randomly selected element from the specified range.
Syntax
random.randrange(start, stop, step)
Parameter |
Description |
start |
Optional. An integer specifying at which position to start. |
stop |
Required. An integer specifying at which position to end. |
step |
Optional. An integer specifying the incrementation. |
Example
Return a number between 3 and 9:
import random
print(random.randrange(3, 9))
#returns a number between 3 (included) and 9 (not included)
Output:
5