|
| | UniformIntDistribution () |
| | Default constructor. Creates a uniform distribution over [0, IntType::max()].
|
| |
| | UniformIntDistribution (IntType a, IntType b=std::numeric_limits< IntType >::max()) |
| | Constructs a uniform distribution with specified bounds.
|
| |
| | UniformIntDistribution (const param_type ¶m) |
| | Constructs from a parameter set.
|
| |
| void | reset () |
| | Resets the distribution state.
|
| |
| IntType | a () const |
| | Gets the lower bound of the distribution range.
|
| |
| IntType | b () const |
| | Gets the upper bound of the distribution range.
|
| |
| 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 minimum value that can be generated (inclusive).
|
| |
| result_type | max () const |
| | Gets the maximum value that can be generated (inclusive).
|
| |
| 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 IntType = int>
class Infinity::Engine::UniformIntDistribution< IntType >
Platform-independent uniform integer distribution.
Produces integer values uniformly distributed over a specified range [a, b] (inclusive). Uses Lemire's algorithm for fast, unbiased bounded random integers, which is both faster and more portable than the rejection sampling used by some standard library implementations.
This implementation guarantees identical results across all platforms when given the same PRNG seed, making it ideal for procedural generation that must be reproducible across different systems.
- Template Parameters
-
| IntType | Integer type (signed or unsigned) |
Example usage:
int roll = dice(rng);
int x = coord_dist(rng);
int y = coord_dist(rng);
uint32_t id = id_gen(rng);
Pseudo-random number generator for procedural generation.
Definition PRNG.hpp:48
- Note
- Both bounds are inclusive; values are in [a, b], not [a, b).
-
Lemire's algorithm ensures perfect uniformity even when the range doesn't divide evenly into the generator's period.
template<typename IntType = int>
template<typename Generator >
Generates the next random value using provided parameters.
Uses Lemire's nearly divisionless algorithm for fast, unbiased random integers. This method is faster than rejection sampling and produces perfectly uniform results even when the range doesn't divide evenly into 2^32.
The algorithm works by:
- Fast path for power-of-2 ranges using simple bit masking
- General path using 64-bit multiplication and rejection sampling only when needed
- 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 uniformly distributed in [param.a(), param.b()] (inclusive)