Tech
[$] Python's two modules for random numbers
Publication: LWN.net
Author: jake
Source published: 06/10/2026, 15:02:09 UTC
Briefing created: 21/10/2026, 23:53:47 UTC
Based on a feed excerpt; full article content has not been acquired. Source evidence retrieved 06/10/2026, 15:50:24 UTC.
Briefings
Python's random and secrets modules both provide random number utilities, but only secrets is suitable for security. Historically, random was used for passwords despite warnings, and in 2015 the core team debated making random secure by default. In 2016, Python 3.6 introduced the secrets module as the secure alternative. The random module remains misused in practice, making its usage patterns instructive for security best practices.
Key points
- The secrets module was introduced in Python 3.6 in 2016 as the secure alternative to the random module for generating passwords and security tokens.
- Historically, the random module was used for passwords and tokens despite documentation warning it is unsuitable for cryptography.
Context
Python's core team debated in 2015 whether to fix the random module's unsuitability for security by making it secure by default. The decision was delayed until 2016 when the secrets module was added to address this issue.
Limitations
Evidence is limited to the 2016 introduction of the secrets module and historical context of random module usage. No specific security test results, adoption statistics, or implementation details of the secrets module are provided.
Generated by Bittrees-hosted qwen35-2b sha256:aaf42c8b7c3c on 21/10/2026, 23:53:47 UTC. Based on publisher-provided feed evidence; may not cover the full original article. Check the source for details.
View archived briefing on IPFS
bafybeibaazfjqyyxjty2rwjzztylv7q57ftdhmns63taj5v3ef4f2a2q4e