WORLDTECH NEWS Global technology intelligence.Contact
← Back to WORLDTECH
Technology SINGLE SOURCE

Python's two modules for random numbers

Close-up of smartphone, tablet, and earphones on a wooden table, bathed in warm lighting.
Illustrative photo.Photo by Hasan Albari on Pexels

What happened

Instead, in 2016, Python 3.6 added a second module: secrets . Python's random and secrets modules both include utilities for obtaining random values, but only one of them is suitable for generating passwords and security tokens.

For much of Python's history, random was used for passwords and tokens anyway, despite documentation that called it unsuitable for cryptography. In 2015, Python's core team debated whether to fix that misuse by making random secure by default. The random module is still misused at times, so it is instructive to look into how the random-number modules should be used.

Sources & evidence