random module

The standard library module for pseudo-random numbers and random choices, such as randrange(10) or choice(colours).

In more detail

randrange(a, b) picks a whole number from a up to but not including b, while randint(a, b) includes b. choice picks one item, shuffle mixes a list in place, sample picks several without repeats and choices picks with repeats. Setting a seed repeats the same sequence, which is useful for tests.

Example

from random import randrange, choice
randrange(1, 7)

Related terms

Taught in

References

Certification courses