Skip to content

random

Supported functions in the Python standard library random module.

choice(seq)

Return a randomly selected element from a non-empty sequence.

Parameters:

Name Type Description Default
seq Sequence[T]

The sequence to choose from.

required

Returns:

Type Description
T

A randomly selected element from the sequence.

randint(a, b)

Return a random integer N such that a <= N <= b.

Parameters:

Name Type Description Default
a int

The lower bound.

required
b int

The upper bound.

required

Returns:

Type Description
int

A randomly selected integer between a and b, inclusive.

random()

Return a random floating point number in the range [0.0, 1.0).

Returns:

Type Description
float

A random float between 0.0 (inclusive) and 1.0 (exclusive).

randrange(start, stop=..., step=...)

randrange(stop: int) -> int
randrange(start: int, stop: int, step: int = ...) -> int

Return a randomly selected element from range(start, stop, step).

Parameters:

Name Type Description Default
start int

The start of the range.

required
stop int

The end of the range.

...
step int

The step size.

...

Returns:

Type Description
int

A randomly selected integer from the range.

shuffle(seq)

Shuffle the sequence in place.

Parameters:

Name Type Description Default
seq MutableSequence[Any]

The mutable sequence to shuffle.

required

uniform(a, b)

Return a random floating point number N such that a <= N <= b.

Parameters:

Name Type Description Default
a float

The lower bound.

required
b float

The upper bound.

required

Returns:

Type Description
float

A random float between a and b.