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

Platform-independent normal (Gaussian) distribution. More...

#include <PRNGDistribution.hpp>

Inheritance diagram for Infinity::Engine::NormalDistribution< RealType >:
[legend]

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

 NormalDistribution ()
 Default constructor. Creates standard normal distribution (mean=0, stddev=1).
 
 NormalDistribution (RealType mean, RealType stddev=RealType(1))
 Constructs a normal distribution with specified parameters.
 
 NormalDistribution (const param_type &param)
 Constructs from a parameter set.
 
void reset ()
 Resets the distribution state.
 
RealType mean () const
 Gets the mean of the distribution.
 
RealType stddev () const
 Gets the standard deviation of the distribution.
 
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 theoretical minimum value (negative infinity).
 
result_type max () const
 Gets the theoretical maximum value (positive infinity).
 
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 NormalDistribution &lhs, const NormalDistribution &rhs)
 
bool operator!= (const NormalDistribution &lhs, const NormalDistribution &rhs)
 

Detailed Description

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

Platform-independent normal (Gaussian) distribution.

Produces floating-point values according to the normal distribution with specified mean and standard deviation. Uses the Box-Muller transform with deterministic uniform distribution to ensure cross-platform reproducibility.

The normal distribution is the familiar bell curve, essential for many natural phenomena and procedural generation tasks like height variation, particle velocities, or noise. This implementation guarantees identical results across all platforms when given the same PRNG seed.

Template Parameters
RealTypeFloating point type (float or double)

Example usage:

PRNG rng(12345);
// Standard normal (mean=0, stddev=1)
float z = standard(rng);
// Custom mean and standard deviation
NormalDistribution<float> heights(170.0f, 10.0f); // mean 170cm, stddev 10cm
float height = heights(rng);
// Generate terrain height variations
NormalDistribution<float> terrain_noise(0.0f, 2.5f);
for (int i = 0; i < 100; ++i) {
float variation = terrain_noise(rng);
}
Platform-independent normal (Gaussian) distribution.
Definition PRNGDistribution.hpp:524
Pseudo-random number generator for procedural generation.
Definition PRNG.hpp:48
Note
Uses Box-Muller transform which generates pairs of values; second value is cached for efficiency. Call reset() to discard cached value if needed.
Results are guaranteed identical across platforms with the same PRNG seed.
Approximately 68% of values fall within ±1 standard deviation of the mean, 95% within ±2 standard deviations, and 99.7% within ±3 standard deviations.

Member Typedef Documentation

◆ result_type

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

The type of values produced by the distribution.

Constructor & Destructor Documentation

◆ NormalDistribution() [1/3]

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

Default constructor. Creates standard normal distribution (mean=0, stddev=1).

◆ NormalDistribution() [2/3]

template<typename RealType = double>
Infinity::Engine::NormalDistribution< RealType >::NormalDistribution ( RealType  mean,
RealType  stddev = RealType(1) 
)
inlineexplicit

Constructs a normal distribution with specified parameters.

Parameters
meanThe mean of the distribution
stddevThe standard deviation of the distribution

◆ NormalDistribution() [3/3]

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

Constructs from a parameter set.

Parameters
paramThe distribution parameters

Member Function Documentation

◆ max()

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

Gets the theoretical maximum value (positive infinity).

◆ mean()

template<typename RealType = double>
RealType Infinity::Engine::NormalDistribution< RealType >::mean ( ) const
inline

Gets the mean of the distribution.

◆ min()

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

Gets the theoretical minimum value (negative infinity).

◆ operator()() [1/2]

template<typename RealType = double>
template<typename Generator >
result_type Infinity::Engine::NormalDistribution< 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 from the normal distribution

◆ operator()() [2/2]

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

Generates the next random value using provided parameters.

Uses the Box-Muller transform to convert two independent uniform random values into two independent standard normal values. The transform generates pairs of values - we return one immediately and cache the second for the next call, improving efficiency by requiring only one pair of uniform samples per two normal values.

The Box-Muller transform: Given U1, U2 ~ Uniform(0,1), compute Z0 = sqrt(-2*ln(U1)) * cos(2*pi*U2) Z1 = sqrt(-2*ln(U1)) * sin(2*pi*U2) where Z0, Z1 ~ Normal(0,1) independently.

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 from Normal(param.mean(), param.stddev())

◆ param() [1/2]

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

Gets the current parameter set.

◆ param() [2/2]

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

Sets new parameters for the distribution.

Also resets the distribution state, discarding any cached value.

Parameters
paramThe new distribution parameters

◆ reset()

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

Resets the distribution state.

Discards any cached value from the Box-Muller transform. This ensures that the next value generated will use fresh random numbers from the generator.

◆ stddev()

template<typename RealType = double>
RealType Infinity::Engine::NormalDistribution< RealType >::stddev ( ) const
inline

Gets the standard deviation of the distribution.

Friends And Related Symbol Documentation

◆ operator!=

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

◆ operator==

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