Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
helios::utils::RandomGenerator< Engine > Class Template Reference

Random number utilities with a user-provided engine. More...

#include <random.hpp>

Public Member Functions

 RandomGenerator (Engine &engine) noexcept
 Constructs a RandomGenerator from an existing engine reference.
 RandomGenerator (const RandomGenerator &) noexcept=default
 RandomGenerator (RandomGenerator &&) noexcept=default
 ~RandomGenerator () noexcept=default
RandomGeneratoroperator= (const RandomGenerator &) noexcept=default
RandomGeneratoroperator= (RandomGenerator &&) noexcept=default
template<typename Dist>
requires Distribution<Dist, Engine>
auto Next (Dist &dist) noexcept(std::is_nothrow_invocable_v< Dist, Engine & >) -> typename Dist::result_type
 Generates a value using the provided distribution.
template<utils::ArithmeticTrait T>
Value ()
 Generates a random arithmetic value using a reasonable default distribution.
template<utils::ArithmeticTrait T, utils::ArithmeticTrait U>
auto ValueFromRange (T min, U max) -> std::common_type_t< T, U >
 Generates a random arithmetic value within the specified range.
Engine & EngineRef () const noexcept
 Provides access to the underlying engine.

Detailed Description

template<RandomEngine Engine>
class helios::utils::RandomGenerator< Engine >

Random number utilities with a user-provided engine.

This wrapper delegates all random generation to an underlying engine instance supplied by the user. It never owns the engine and does not perform any static initialization of engines itself.

Template Parameters
EngineRandomEngine type used for generation

Definition at line 133 of file random.hpp.

Constructor & Destructor Documentation

◆ RandomGenerator() [1/3]

template<RandomEngine Engine>
helios::utils::RandomGenerator< Engine >::RandomGenerator ( Engine & engine)
inlineexplicitnoexcept

Constructs a RandomGenerator from an existing engine reference.

The engine is not owned and must outlive this object.

Parameters
engineReference to engine used for random generation

Definition at line 140 of file random.hpp.

◆ RandomGenerator() [2/3]

template<RandomEngine Engine>
helios::utils::RandomGenerator< Engine >::RandomGenerator ( const RandomGenerator< Engine > & )
defaultnoexcept

◆ RandomGenerator() [3/3]

template<RandomEngine Engine>
helios::utils::RandomGenerator< Engine >::RandomGenerator ( RandomGenerator< Engine > && )
defaultnoexcept

◆ ~RandomGenerator()

template<RandomEngine Engine>
helios::utils::RandomGenerator< Engine >::~RandomGenerator ( )
defaultnoexcept

Member Function Documentation

◆ EngineRef()

template<RandomEngine Engine>
Engine & helios::utils::RandomGenerator< Engine >::EngineRef ( ) const
inlinenodiscardnoexcept

Provides access to the underlying engine.

Returns
Reference to the engine used by this generator

Definition at line 197 of file random.hpp.

◆ Next()

template<RandomEngine Engine>
template<typename Dist>
requires Distribution<Dist, Engine>
auto helios::utils::RandomGenerator< Engine >::Next ( Dist & dist) -> typename Dist::result_type
inlinenodiscardnoexcept

Generates a value using the provided distribution.

This is a low-level interface that accepts an arbitrary distribution object. Intended for cases where caller needs full control over distribution parameters.

Template Parameters
DistDistribution type compatible with Engine
Parameters
distDistribution instance used for generation
Returns
Generated random value of type Dist::result_type

Definition at line 159 of file random.hpp.

◆ operator=() [1/2]

template<RandomEngine Engine>
RandomGenerator & helios::utils::RandomGenerator< Engine >::operator= ( const RandomGenerator< Engine > & )
defaultnoexcept

◆ operator=() [2/2]

template<RandomEngine Engine>
RandomGenerator & helios::utils::RandomGenerator< Engine >::operator= ( RandomGenerator< Engine > && )
defaultnoexcept

◆ Value()

template<RandomEngine Engine>
template<utils::ArithmeticTrait T>
T helios::utils::RandomGenerator< Engine >::Value ( )
inlinenodiscard

Generates a random arithmetic value using a reasonable default distribution.

For integral types, uses std::uniform_int_distribution over the full representable range, except for bool which uses a uniform {false, true}. For floating point types, uses std::uniform_real_distribution in the [0, 1) range to avoid dependence on std::numeric_limits<>::min().

Template Parameters
TArithmetic type to generate
Returns
Randomly generated value of type T

Definition at line 205 of file random.hpp.

◆ ValueFromRange()

template<RandomEngine Engine>
template<utils::ArithmeticTrait T, utils::ArithmeticTrait U>
auto helios::utils::RandomGenerator< Engine >::ValueFromRange ( T min,
U max ) -> std::common_type_t< T, U >
inlinenodiscard

Generates a random arithmetic value within the specified range.

For integral types, uses std::uniform_int_distribution with closed interval [min, max]. For floating point types, uses std::uniform_real_distribution with interval [min, max).

Template Parameters
TArithmetic type
UArithmetic type
Parameters
minLower bound of the range
maxUpper bound of the range
Returns
Random value of std::common_type_t<T, U> within [min, max] or [min, max)

Definition at line 225 of file random.hpp.