CSPRNG
acronymKept in this browser · My desk
Stands for: cryptographically strong pseudo-random number generator
A random number generator whose output cannot be predicted from earlier output, suitable for keys, tokens, salts and nonces; PEP 506 defines it as resistant to prediction.
Python's random module uses the Mersenne Twister, which its documentation calls completely deterministic and completely unsuitable for cryptographic purposes. The secrets module, added in Python 3.6 by PEP 506, and os.urandom() draw on the operating system's most secure source instead; secrets.token_bytes(), token_hex() and token_urlsafe() default to 32 bytes today, a value the documentation says may change.
Also known as: cryptographically secure pseudorandom number generator, secrets module, os.urandom
Sources
- PEP 506, Adding A Secrets Module To The Standard Library (read 2026-10-27): CSPRNG, an algorithm whose output is resistant to prediction; the Mersenne Twister of the random module
- Python 3.13 documentation, secrets (read 2026-10-27): the most secure source of randomness the operating system provides; DEFAULT_ENTROPY may change
- Python 3.13 documentation, random (read 2026-10-27): completely deterministic, completely unsuitable for cryptographic purposes