class documentation

class RandomFactory: (source)

View In Hierarchy

Factory providing secureRandom and insecureRandom methods.

You shouldn't have to instantiate this class, use the module level functions instead: it is an implementation detail and could be removed or changed arbitrarily.

Method insecureRandom Return a number of non secure random bytes.
Method secureRandom Return a number of secure random bytes.
Class Variable randomSources Undocumented
Method _osUrandom Wrapper around os.urandom that cleanly manage its absence.
Method _randBits Wrapper around os.getrandbits.
Method _randModule Wrapper around the random module.
Constant _BYTES Undocumented
def insecureRandom(self, nbytes: int) -> bytes: (source)

Return a number of non secure random bytes.

Parameters
nbytes:intnumber of bytes to generate.
Returns
stra string of random bytes.
def secureRandom(self, nbytes: int, fallback: bool = False) -> bytes: (source)

Return a number of secure random bytes.

Parameters
nbytes:intnumber of bytes to generate.
fallback:boolWhether the function should fallback on non-secure random or not. Default to False.
Returns
stra string of random bytes.
randomSources: tuple = (source)

Undocumented

def _osUrandom(self, nbytes: int) -> bytes: (source)

Wrapper around os.urandom that cleanly manage its absence.

def _randBits(self, nbytes: int) -> bytes: (source)

Wrapper around os.getrandbits.

def _randModule(self, nbytes: int) -> bytes: (source)

Wrapper around the random module.

Undocumented

Value
_maketrans(b'', b'')