Raven Engine v0.1
A modern 3D Game Engine
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 (u64 initState, u64 initseq) noexcept
 Seeds the generator with explicit state and sequence values.
u32 Next () noexcept
 Generates the next 32-bit pseudorandom number.
u32 Next (u32 min, u32 max) noexcept
 Generates a 32-bit integer uniformly in [min, max).
u32 Next (u32 max) noexcept
 Generates a 32-bit integer uniformly in [0, max).
f32 NextFloat () noexcept
 Generates a f32ing-point number uniformly in [0.0, 1.0).
f32 NextFloat (f32 min, f32 max) noexcept
 Generates a f32 uniformly in [min, max).
f32 NextFloat (f32 max) noexcept
 Generates a f32 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]

u32 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]

u32 Crux::RandomEngine::Next ( u32 max)
inlinenoexcept

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

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

◆ Next() [3/3]

u32 Crux::RandomEngine::Next ( u32 min,
u32 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]

f32 Crux::RandomEngine::NextFloat ( )
inlinenoexcept

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

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

Returns
f32 in [0.0f, 1.0f).

◆ NextFloat() [2/3]

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

Generates a f32 uniformly in [0.0, max).

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

◆ NextFloat() [3/3]

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

Generates a f32 uniformly in [min, max).

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

◆ Seed()

void Crux::RandomEngine::Seed ( u64 initState,
u64 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: