Raven Engine v0.1
Loading...
Searching...
No Matches
Crux::RandomEngine Class Reference

High-performance 64-bit state, 32-bit output PRNG based on PCG32. More...

#include <RandomEngine.h>

Public Member Functions

 RandomEngine () noexcept
 Default constructor initializes state and stream to constants.
void Seed (unsigned long long initState, unsigned long long initseq) noexcept
 Seeds the generator with explicit state and sequence values.
unsigned int Next () noexcept
 Generates the next 32-bit pseudorandom number.
unsigned int Next (unsigned int min, unsigned int max) noexcept
 Generates a 32-bit integer uniformly in [min, max).
unsigned int Next (unsigned int max) noexcept
 Generates a 32-bit integer uniformly in [0, max).
float NextFloat () noexcept
 Generates a floating-point number uniformly in [0.0, 1.0).
float NextFloat (float min, float max) noexcept
 Generates a float uniformly in [min, max).
float NextFloat (float max) noexcept
 Generates a float uniformly in [0.0, max).

Detailed Description

High-performance 64-bit state, 32-bit output PRNG based on PCG32.

Uses a Linear Congruential Generator (LCG) to advance a 64-bit state, then applies an xorshift and bit-rotation to produce a 32-bit pseudorandom result.

Constructor & Destructor Documentation

◆ RandomEngine()

Crux::RandomEngine::RandomEngine ( )
inlinenoexcept

Default constructor initializes state and stream to constants.

Member Function Documentation

◆ Next() [1/3]

unsigned int Crux::RandomEngine::Next ( )
inlinenoexcept

Generates the next 32-bit pseudorandom number.

Advances the internal 64-bit state then applies the PCG output transformation: xorshifted = ((oldstate >> 18) ^ oldstate) >> 27; rot = oldstate >> 59; result = rotate_right(xorshifted, rot);

Returns
32-bit unsigned pseudorandom value.

◆ Next() [2/3]

unsigned int Crux::RandomEngine::Next ( unsigned int max)
inlinenoexcept

Generates a 32-bit integer uniformly in [0, max).

Parameters
maxExclusive upper bound.
Returns
Pseudorandom integer in [0, max).

◆ Next() [3/3]

unsigned int Crux::RandomEngine::Next ( unsigned int min,
unsigned int max )
inlinenoexcept

Generates a 32-bit integer uniformly in [min, max).

Parameters
minInclusive lower bound.
maxExclusive upper bound.
Returns
Pseudorandom integer in [min, max). Returns min if min >= max.

◆ NextFloat() [1/3]

float Crux::RandomEngine::NextFloat ( )
inlinenoexcept

Generates a floating-point number uniformly in [0.0, 1.0).

Scales Next() output by 1/2^32.

Returns
Float in [0.0f, 1.0f).

◆ NextFloat() [2/3]

float Crux::RandomEngine::NextFloat ( float max)
inlinenoexcept

Generates a float uniformly in [0.0, max).

Parameters
maxExclusive upper bound.
Returns
Float in [0.0f, max).

◆ NextFloat() [3/3]

float Crux::RandomEngine::NextFloat ( float min,
float max )
inlinenoexcept

Generates a float uniformly in [min, max).

Parameters
minInclusive lower bound.
maxExclusive upper bound.
Returns
Float in [min, max). Returns min if min >= max.

◆ Seed()

void Crux::RandomEngine::Seed ( unsigned long long initState,
unsigned long long initseq )
inlinenoexcept

Seeds the generator with explicit state and sequence values.

Proper seeding procedure ensures avoidance of the all-zero state:

  1. Sets state to zero and increment to (initseq << 1) | 1.
  2. Advances one step.
  3. Mixes initState into state.
  4. Advances again.
Parameters
initState64-bit initial state seed.
initseq64-bit sequence seed (stream selector).

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