What is the name of the Python module for generating random numbers?

The story behind the answer

The Python module for generating random numbers is `random`.

Python’s standard-library `random` module provides pseudorandom generators and related functions. For example, `random.randint(1, 6)` can produce an integer from 1 through 6, while `random.choice(sequence)` selects an item from a sequence. The module also supports shuffling, sampling, and generating values from distributions such as uniform and Gaussian distributions.

The numbers are pseudorandom rather than genuinely random: they are produced by a deterministic algorithm initialized from a seed. Calling `random.seed()` can make a sequence repeatable, which is useful for tests, simulations, and classroom examples. The default generator is designed for general-purpose modeling and games, not for passwords, authentication tokens, or cryptographic keys.

For security-sensitive randomness, Python provides the `secrets` module, which draws from a stronger source intended for secret values. `numpy.random` belongs to NumPy and is optimized for numerical arrays, while `statistics` analyzes data and `math` supplies mathematical functions. Those modules may be used alongside `random`, but they are not the standard module named by this question.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: