RandomMixin

Mixin class that provides helper randomness functions.

Synopsis

Declared in <random.h>

template<typename T>
class RandomMixin;

Description

Intended to be used through CRTP: https://en.cppreference.com/w/cpp/language/crtp. An RNG class FunkyRNG would derive publicly from RandomMixin<FunkyRNG>. This permits RandomMixin from accessing the derived class's rand64() function, while also allowing the derived class to provide more.

The derived class must satisfy the RandomNumberGenerator concept.

Type Aliases

NameDescription
result_type Result type of the generator, for the UniformRandomBitGenerator concept.

Member Functions

NameDescription
RandomMixin [constructor]Constructors
operator= Assignment operators
fillrand Fill a span with random bytes.
operator() Generate the next random value, for the UniformRandomBitGenerator concept.
rand Generate a random integer in its entire (non-negative) range.
rand256 generate a random uint256.
rand32 Generate a random 32-bit integer.
rand_exp_duration Return a duration sampled from an exponential distribution (https://en.wikipedia.org/wiki/Exponential_distribution). Successive events whose intervals are distributed according to this form a memoryless Poisson process. This should be used for repeated network events (e.g. sending a certain type of message) to minimize leaking information to observers.
rand_uniform_delay Return the time point advanced by a uniform random duration.
rand_uniform_duration Generate a uniform random duration in the range from 0 (inclusive) to range (exclusive).
randbits randbits overloads
randbool Generate a random boolean.
randbytes randbytes overloads
randrange randrange overloads

Static Member Functions

NameDescription
max Largest value the generator can produce.
min Smallest value the generator can produce.

Protected Member Functions

NameDescription
FlushCache Discard any random bits buffered from a previous rand64() call.

Derived Classes

NameDescription
FastRandomContext Fast randomness source. This is seeded once with secure random data, but is completely deterministic and does not gather more entropy after that.
InsecureRandomContext xoroshiro128++ PRNG. Extremely fast, not appropriate for cryptographic purposes.