Danger

Nothing here should be used for any security purposes.

  • If you need cryptographic tools in a Python environment use pyca.

  • If you need efficient and reliable abstract math utilities in a Python-like environment consider using SageMath.

Random Numbers

This module is imported with:

import toy_crypto.rand

For the most part, the functions here duplicate some utilities from random, but use the cryptographically secure random number generator from secrets.

The rand functions

toy_crypto.rand.random() float

returns a 32-bit float in [0.0, 1.0)

Return type:

float

toy_crypto.rand.randrange(*args: int) int

Like random.randrange(), but uses RNG from secrets.

Parameters:

args (int)

Return type:

int

toy_crypto.rand.shuffle(x: MutableSequence[Any]) None

Like random.shuffle(), but uses RNG from secrets.

Parameters:

x (MutableSequence[Any])

Return type:

None