random.randrange

Full name
random.randrange
Library
random
Syntax

random.randrange(stop)

random.randrange(start, stop[, step])

Description

The random.randrange function returns a random element extracted from the sequence of integers generated by range (start, stop, step).

Parameters
  • start: First number a in the sequence.
  • stop: Limit value of the sequence.
  • step: (Optional) value to add to each number to generate the next one.
Result

The random.randrange function returns an integer.

Examples

We can generate a random integer extracted from the sequence [2, 4, 6, 8] with the following code:

random.randrange(2, 9, 2)
6

Note that the number 9 has been used as the second argument since the sequence from which to perform the extraction does not include the stop value.

Submitted by admin on Tue, 02/23/2021 - 09:33