Pigweed
 
Loading...
Searching...
No Matches
pw::random::RandomGenerator Class Referenceabstract

#include <random.h>

Inheritance diagram for pw::random::RandomGenerator:
pw::random::XorShiftStarRng64

Public Member Functions

template<class T >
void GetInt (T &dest)
 
template<class T >
void GetInt (T &dest, const T &exclusive_upper_bound)
 
virtual void Get (ByteSpan dest)=0
 
virtual void InjectEntropyBits (uint32_t data, uint_fast8_t num_bits)=0
 
void InjectEntropy (ConstByteSpan data)
 Injects entropy into the pool byte-by-byte.
 

Detailed Description

A random generator uses injected entropy to generate random values. Many of the guarantees for this interface are provided at the level of the implementations. In general:

  • DO assume a generator will always succeed.
  • DO NOT assume a generator is cryptographically secure.
  • DO NOT assume uniformity of generated data.

Member Function Documentation

◆ Get()

virtual void pw::random::RandomGenerator::Get ( ByteSpan  dest)
pure virtual

Populates the destination buffer with a randomly generated value.

Parameters
[out]destThe destination buffer.

Implemented in pw::random::XorShiftStarRng64.

◆ GetInt()

template<class T >
void pw::random::RandomGenerator::GetInt ( T &  dest,
const T &  exclusive_upper_bound 
)
inline

Calculates a uniformly distributed random number in the range [0, exclusive_upper_bound).

This avoids modulo biasing. Uniformity is only guaranteed if the underlying generator generates uniform data. Uniformity is achieved by generating new random numbers until one is generated in the desired range (with optimizations).

Parameters
[out]destThe destination to populate the random number into.
[in]exclusive_upper_boundThe largest number that can be populated into dest, exclusive.

◆ InjectEntropyBits()

virtual void pw::random::RandomGenerator::InjectEntropyBits ( uint32_t  data,
uint_fast8_t  num_bits 
)
pure virtual

Injects entropy into the pool.

Parameters
[in]dataUp to 32 bits of random entropy data.
[in]num_bitsThe number of bits of entropy. If less than 32, entropy is assumed to be stored in the least significant bits of data.

Implemented in pw::random::XorShiftStarRng64.


The documentation for this class was generated from the following file: