template<typename IntType = int>
class Infinity::Engine::GeometricDistribution< IntType >
Platform-independent geometric distribution.
Produces integer counts representing the number of failures before the first success in a sequence of independent Bernoulli trials with success probability p. This is the discrete analog of the exponential distribution.
The geometric distribution models waiting time scenarios like the number of attempts before success, or time until first event. It's the only discrete distribution with the memoryless property, making it ideal for modeling random "first occurrence" events.
- Template Parameters
-
| IntType | Integer type for the result |
Example usage:
int failures_before_success = attempts(rng);
int attempts_needed = item_drops(rng);
int failed_spawns = spawn_tries(rng);
int attacks_until_crit = crit_attempts(rng);
Platform-independent geometric distribution.
Definition PRNGDistribution.hpp:2905
Pseudo-random number generator for procedural generation.
Definition PRNG.hpp:48
- Note
- Returns values in [0, ∞) representing failures before first success.
-
Memoryless property: P(X = n+k | X >= n) = P(X = k).
-
Mean = (1-p)/p, Variance = (1-p)/p².
-
For p = 0.5, expected value is 1 (one failure before success on average).
template<typename IntType = int>
template<typename Generator >
Generates the next random value using provided parameters.
Uses the inverse CDF method with logarithms: X = ceil(ln(U) / ln(1-p)) - 1 where U ~ Uniform(0, 1) and X ~ Geometric(p).
This method is efficient and exact, requiring only one uniform sample and two logarithm computations.
- 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 count of failures before first success