Raven Engine v0.1
Loading...
Searching...
No Matches
Random

Random number generation and entropy tools. More...

Classes

class  Crux::Random
 Static wrapper around RandomEngine for convenience. More...
class  Crux::RandomEngine
 High-performance 64-bit state, 32-bit output PRNG based on PCG32. More...

Functions

std::pair< unsigned long long, unsigned long long > Crux::Entropy::GetSeedPair () noexcept
 Retrieves a seed pair for random number generation.
void Crux::Entropy::ForceSeed (unsigned long long state, unsigned long long seq) noexcept
 Overrides entropy generation with a forced seed pair.
void Crux::Entropy::ClearForcedSeed ()
 Clears any previously forced seed, restoring normal entropy behavior.

Detailed Description

Random number generation and entropy tools.

Encapsulates RNG engines, entropy sources, and distribution logic.

Function Documentation

◆ ClearForcedSeed()

void Crux::Entropy::ClearForcedSeed ( )

Clears any previously forced seed, restoring normal entropy behavior.

After calling this, GetSeedPair will resume fetching entropy from system or fallback sources. Useful to reset after deterministic testing scenarios.

◆ ForceSeed()

void Crux::Entropy::ForceSeed ( unsigned long long state,
unsigned long long seq )
noexcept

Overrides entropy generation with a forced seed pair.

Useful for deterministic behavior in testing or debugging scenarios. Once set, subsequent calls to GetSeedPair will return the forced values until the application resets or explicitly clears them.

Parameters
stateThe internal state seed value.
seqThe stream sequence seed value.

◆ GetSeedPair()

std::pair< unsigned long long, unsigned long long > Crux::Entropy::GetSeedPair ( )
noexcept

Retrieves a seed pair for random number generation.

This function attempts to obtain a pair of 64-bit values to be used as the initial state and stream sequence for deterministic random number engines.

The seed source priority is as follows:

  1. User-forced seeds (via ForceSeed)
  2. std::random_device
  3. OS entropy (e.g., /dev/urandom or BCryptGenRandom)
  4. Fallback entropy (TSC, clock, PID, hashed)
Returns
A std::pair containing the state and sequence seed.