mbedtls.secrets Module

Generate secure random numbers.

This is an implementation of the PEP 506 API based on a CSPRNG (Cryptographically Strong Pseudo Random Number Generator).

This module is compatibale with the standard secrets (PEP 506) module.

mbedtls.secrets.randbits()

Generate an int with k random bits.

mbedtls.secrets.choice()

Return a random element from seq.

mbedtls.secrets.randbelow(upper_bound)[source]

Return a random int in the range [0, n).

mbedtls.secrets.token_bytes(nbytes=None)[source]

Return a random byte string containing nbytes number of bytes.

If nbytes is None or not supplied, a reasonable default is used.

mbedtls.secrets.token_hex(nbytes=None)[source]

Return a random text string, in hexadecimal.

mbedtls.secrets.token_urlsafe(nbytes=None)[source]

Return a random URL-safe string.