3 ms·
If you have a modern version of Python, you can do: import secrets secrets.token_bytes() # returns a randomized token You can pass in the number of bytes
by deathanatos 9y ago
If you have a modern version of Python, you can do:
import secrets
secrets.token_bytes() # returns a randomized token
You can pass in the number of bytes you want, but I would think it would be better to rely on the default (presently 256 bit). This module is intended for cryptographic purposes. There are also helper functions to get a hex string or a URL safe string back.
https://docs.python.org/3/library/secrets.html https://docs.python.org/3/library/secrets.html