Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Engine::UniformRealDistribution< RealType > Class Template Reference

Platform-independent uniform real distribution. More...

#include <PRNGDistribution.hpp>

Classes

struct  param_type
 Parameter set for the distribution. More...
 

Public Types

using result_type = RealType
 The type of values produced by the distribution.
 

Public Member Functions

 UniformRealDistribution ()
 Default constructor. Creates a uniform distribution over [0, 1).
 
 UniformRealDistribution (RealType a, RealType b=RealType(1))
 Constructs a uniform distribution with specified bounds.
 
 UniformRealDistribution (const param_type &param)
 Constructs from a parameter set.
 
void reset ()
 Resets the distribution state.
 
RealType a () const
 Gets the lower bound of the distribution range.
 
RealType b () const
 Gets the upper bound of the distribution range.
 
param_type param () const
 Gets the current parameter set.
 
void param (const param_type &param)
 Sets new parameters for the distribution.
 
result_type min () const
 Gets the minimum value that can be generated (inclusive).
 
result_type max () const
 Gets the maximum value that can be generated (exclusive).
 
template<typename Generator >
result_type operator() (Generator &g)
 Generates the next random value using stored parameters.
 
template<typename Generator >
result_type operator() (Generator &g, const param_type &param)
 Generates the next random value using provided parameters.
 

Friends

bool operator== (const UniformRealDistribution &lhs, const UniformRealDistribution &rhs)
 
bool operator!= (const UniformRealDistribution &lhs, const UniformRealDistribution &rhs)
 

Detailed Description

template<typename RealType = double>
class Infinity::Engine::UniformRealDistribution< RealType >

Platform-independent uniform real distribution.

Produces floating-point values uniformly distributed over a specified range [a, b). Unlike std::uniform_real_distribution, this implementation guarantees identical results across different platforms and compilers by using a deterministic uint32 to float conversion method.

This distribution is essential for procedural generation where cross-platform reproducibility is critical. The same seed will produce identical sequences on Windows, Linux, and macOS regardless of compiler or standard library implementation.

Template Parameters
RealTypeFloating point type (float or double)

Example usage:

PRNG rng(12345);
float value = dist(rng); // Random float in [0, 10)
// Generate multiple values
for (int i = 0; i < 100; ++i) {
float x = dist(rng);
}
// Change parameters without creating new distribution
float normalized = dist(rng); // Now in [-1, 1)
Pseudo-random number generator for procedural generation.
Definition PRNG.hpp:48
Platform-independent uniform real distribution.
Definition PRNGDistribution.hpp:55
Parameter set for the distribution.
Definition PRNGDistribution.hpp:69
Note
Results are guaranteed identical across platforms when using the same PRNG seed.
Warning
The upper bound b is exclusive; values are in [a, b), not [a, b].

Member Typedef Documentation

◆ result_type

template<typename RealType = double>
using Infinity::Engine::UniformRealDistribution< RealType >::result_type = RealType

The type of values produced by the distribution.

Constructor & Destructor Documentation

◆ UniformRealDistribution() [1/3]

template<typename RealType = double>
Infinity::Engine::UniformRealDistribution< RealType >::UniformRealDistribution ( )
inline

Default constructor. Creates a uniform distribution over [0, 1).

◆ UniformRealDistribution() [2/3]

template<typename RealType = double>
Infinity::Engine::UniformRealDistribution< RealType >::UniformRealDistribution ( RealType  a,
RealType  b = RealType(1) 
)
inlineexplicit

Constructs a uniform distribution with specified bounds.

Parameters
aLower bound (inclusive)
bUpper bound (exclusive), defaults to 1

◆ UniformRealDistribution() [3/3]

template<typename RealType = double>
Infinity::Engine::UniformRealDistribution< RealType >::UniformRealDistribution ( const param_type param)
inlineexplicit

Constructs from a parameter set.

Parameters
paramThe distribution parameters

Member Function Documentation

◆ a()

template<typename RealType = double>
RealType Infinity::Engine::UniformRealDistribution< RealType >::a ( ) const
inline

Gets the lower bound of the distribution range.

◆ b()

template<typename RealType = double>
RealType Infinity::Engine::UniformRealDistribution< RealType >::b ( ) const
inline

Gets the upper bound of the distribution range.

◆ max()

template<typename RealType = double>
result_type Infinity::Engine::UniformRealDistribution< RealType >::max ( ) const
inline

Gets the maximum value that can be generated (exclusive).

◆ min()

template<typename RealType = double>
result_type Infinity::Engine::UniformRealDistribution< RealType >::min ( ) const
inline

Gets the minimum value that can be generated (inclusive).

◆ operator()() [1/2]

template<typename RealType = double>
template<typename Generator >
result_type Infinity::Engine::UniformRealDistribution< RealType >::operator() ( Generator &  g)
inline

Generates the next random value using stored parameters.

Template Parameters
GeneratorThe random number generator type (e.g., PRNG)
Parameters
gThe random number generator
Returns
A random value uniformly distributed in [a, b)

◆ operator()() [2/2]

template<typename RealType = double>
template<typename Generator >
result_type Infinity::Engine::UniformRealDistribution< RealType >::operator() ( Generator &  g,
const param_type param 
)
inline

Generates the next random value using provided parameters.

Uses a deterministic conversion from uint32 to floating point that ensures identical results across all platforms and compilers. The conversion divides by exactly 2^32 to map the full uint32 range to [0, 1).

Template Parameters
GeneratorThe random number generator type (e.g., PRNG)
Parameters
gThe random number generator
paramThe distribution parameters to use for this generation
Returns
A random value uniformly distributed in [param.a(), param.b())

◆ param() [1/2]

template<typename RealType = double>
param_type Infinity::Engine::UniformRealDistribution< RealType >::param ( ) const
inline

Gets the current parameter set.

◆ param() [2/2]

template<typename RealType = double>
void Infinity::Engine::UniformRealDistribution< RealType >::param ( const param_type param)
inline

Sets new parameters for the distribution.

◆ reset()

template<typename RealType = double>
void Infinity::Engine::UniformRealDistribution< RealType >::reset ( )
inline

Resets the distribution state.

No-op for uniform distributions as they maintain no internal state between generations.

Friends And Related Symbol Documentation

◆ operator!=

template<typename RealType = double>
bool operator!= ( const UniformRealDistribution< RealType > &  lhs,
const UniformRealDistribution< RealType > &  rhs 
)
friend

◆ operator==

template<typename RealType = double>
bool operator== ( const UniformRealDistribution< RealType > &  lhs,
const UniformRealDistribution< RealType > &  rhs 
)
friend