Danger
Nothing here should be used for any security purposes.
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.choices(population: Sequence, weights: Sequence[float] | None = None, *, cum_weights: Sequence[float] | None = None, k: int = 1) Sequence [source]¶
Return a k sized list of population elements chosen with replacement.
If the relative weights or cumulative weights are not specified, the selections are made with equal probability.
This is the same as
random.choices()
except that it uses the the random number generator from :py:mod:1secrets`. Indeed, the implementation is just copied from that source.
- toy_crypto.rand.randrange(*args: int) int [source]¶
Like
random.randrange()
, but uses RNG fromsecrets
.
- toy_crypto.rand.shuffle(x: MutableSequence[Any]) None [source]¶
Like
random.shuffle()
, but uses RNG fromsecrets
.- Parameters:
x (
MutableSequence
[Any
])- Return type: