|
Infinity Engine v0.6.20
C++ API Documentation
|
Pseudo-random number generator for procedural generation. More...
#include <PRNG.hpp>
Public Types | |
| typedef uint32_t | result_type |
| Result type for compatibility with standard library distributions. | |
Public Member Functions | |
| PRNG () | |
| Default constructor. | |
| PRNG (uint64_t seed, uint64_t stream=0) | |
| Constructs a PRNG with the specified seed and stream. | |
| ~PRNG () | |
| Destructor. | |
| void | setSeed (uint64_t seed, uint64_t stream=0) |
| Sets the seed and stream for the random number generator. | |
| uint64_t | getSeed () const |
| Gets the current seed value. | |
| uint64_t | getStream () const |
| Gets the current stream identifier. | |
| uint32_t | operator() () |
| Function call operator for generating random uint32 values. | |
| uint32_t | operator() (uint32_t upper_bound) |
| Function call operator for generating bounded random uint32 values. | |
| uint32_t | next () |
| Generates the next random uint32 value. | |
| int | nextInt () |
| Generates a random integer value. | |
| float | nextFloat () |
| Generates a random float value in the range [0, 1). | |
| uint32_t | nextBounded (uint32_t l, uint32_t u) |
| Generates a random uint32 value within the specified inclusive range. | |
| int | nextIntBounded (int l, int u) |
| Generates a random integer value within the specified inclusive range. | |
| float | nextFloatBounded (float l, float u) |
| Generates a random float value within the specified inclusive range. | |
| void | advance (uint64_t delta) |
| Advances the generator state forward by delta steps. | |
| void | backstep (uint64_t delta) |
| Steps the generator state backward by delta steps. | |
| void | discard (uint64_t delta) |
| Discards delta random values from the sequence. | |
Static Public Member Functions | |
| static uint64_t | createSeed () |
| Creates a new random seed using system entropy. | |
| static constexpr size_t | period_pow2 () |
| Returns the period of the generator as a power of 2. | |
| static constexpr uint32_t | min () |
| Returns the minimum value the generator can produce. | |
| static constexpr uint32_t | max () |
| Returns the maximum value the generator can produce. | |
Pseudo-random number generator for procedural generation.
PRNG provides a high-quality, fast pseudo-random number generator based on the PCG (Permuted Congruential Generator) algorithm. It offers excellent statistical properties, good performance, and reproducibility from seeds, making it ideal for procedural generation workflows.
The generator supports:
Streams: PCG generators support multiple independent streams, allowing you to use the same seed but get completely different, uncorrelated sequences. This is useful for generating different aspects of procedural content (e.g., terrain, vegetation, weather) from a single master seed while maintaining independence between systems.
Example usage:
| typedef uint32_t Infinity::Engine::PRNG::result_type |
Result type for compatibility with standard library distributions.
| Infinity::Engine::PRNG::PRNG | ( | ) |
Default constructor.
Creates a PRNG with a seed generated from PRNG::createSeed() and stream 0.
| Infinity::Engine::PRNG::PRNG | ( | uint64_t | seed, |
| uint64_t | stream = 0 |
||
| ) |
Constructs a PRNG with the specified seed and stream.
| seed | The seed value for reproducible random number generation. |
| stream | The stream identifier (default 0). Different streams with the same seed produce independent, uncorrelated sequences. |
| Infinity::Engine::PRNG::~PRNG | ( | ) |
Destructor.
|
inline |
Advances the generator state forward by delta steps.
Efficiently jumps ahead in the random number sequence without generating intermediate values. Useful for parallel generation or skipping ahead.
| delta | Number of steps to advance. |
|
inline |
Steps the generator state backward by delta steps.
Efficiently jumps backward in the random number sequence.
| delta | Number of steps to backstep. |
|
static |
Creates a new random seed using system entropy.
Entropy sources by quality:
High-quality (always varying):
Medium-quality (varies per run):
Low-quality (rarely changes):
Constant per build:
|
inline |
Discards delta random values from the sequence.
Equivalent to calling next() delta times, but more efficient.
| delta | Number of values to discard. |
|
inline |
Gets the current seed value.
|
inline |
Gets the current stream identifier.
|
inlinestaticconstexpr |
Returns the maximum value the generator can produce.
|
inlinestaticconstexpr |
Returns the minimum value the generator can produce.
|
inline |
Generates the next random uint32 value.
| uint32_t Infinity::Engine::PRNG::nextBounded | ( | uint32_t | l, |
| uint32_t | u | ||
| ) |
Generates a random uint32 value within the specified inclusive range.
| l | Lower bound (inclusive). |
| u | Upper bound (inclusive). |
| float Infinity::Engine::PRNG::nextFloat | ( | ) |
Generates a random float value in the range [0, 1).
| float Infinity::Engine::PRNG::nextFloatBounded | ( | float | l, |
| float | u | ||
| ) |
Generates a random float value within the specified inclusive range.
| l | Lower bound (inclusive). |
| u | Upper bound (inclusive). |
| int Infinity::Engine::PRNG::nextInt | ( | ) |
Generates a random integer value.
| int Infinity::Engine::PRNG::nextIntBounded | ( | int | l, |
| int | u | ||
| ) |
Generates a random integer value within the specified inclusive range.
| l | Lower bound (inclusive). |
| u | Upper bound (inclusive). |
|
inline |
Function call operator for generating random uint32 values.
|
inline |
Function call operator for generating bounded random uint32 values.
| upper_bound | Exclusive upper bound (result will be in [0, upper_bound)). |
|
inlinestaticconstexpr |
Returns the period of the generator as a power of 2.
| void Infinity::Engine::PRNG::setSeed | ( | uint64_t | seed, |
| uint64_t | stream = 0 |
||
| ) |
Sets the seed and stream for the random number generator.
Resets the generator state to produce a deterministic sequence from the given seed and stream combination.
| seed | The new seed value. |
| stream | The stream identifier (default 0). |