|
| | 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 ¶m) |
| | 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 ¶m) |
| | 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 ¶m) |
| | Generates the next random value using provided parameters.
|
| |
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
-
| RealType | Floating point type (float or double) |
Example usage:
float z = standard(rng);
float height = heights(rng);
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.
template<typename RealType = double>
template<typename Generator >
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
-
| Generator | The random number generator type (e.g., PRNG) |
- Parameters
-
| g | The random number generator |
| param | The distribution parameters to use for this generation |
- Returns
- A random value from Normal(param.mean(), param.stddev())