|
| | DiscreteDistribution () |
| | Default constructor. Creates uniform distribution over {0}.
|
| |
| template<typename InputIterator > |
| | DiscreteDistribution (InputIterator first, InputIterator last) |
| | Constructs from iterator range of weights.
|
| |
| | DiscreteDistribution (std::initializer_list< double > wl) |
| | Constructs from initializer list of weights.
|
| |
| template<typename UnaryOperation > |
| | DiscreteDistribution (size_t count, double xmin, double xmax, UnaryOperation fw) |
| | Constructs from function evaluated at intervals.
|
| |
| | DiscreteDistribution (const param_type ¶m) |
| | Constructs from a parameter set.
|
| |
| void | reset () |
| | Resets the distribution state.
|
| |
| std::vector< double > | probabilities () const |
| | Returns the probability vector.
|
| |
| 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 (0).
|
| |
| result_type | max () const |
| | Gets the maximum value that can be generated.
|
| |
| 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::DiscreteDistribution< IntType >
Platform-independent discrete distribution with arbitrary probabilities.
Produces random integers i where 0 <= i < n, distributed according to a discrete probability mass function specified by weights. Each integer has a probability proportional to its weight, making this ideal for weighted random selection.
This distribution is extremely versatile for procedural generation and game logic where different outcomes have different probabilities that don't fit standard distributions. Examples include loot tables, weighted random selection, probability tables, or any scenario requiring custom discrete probabilities.
- Template Parameters
-
| IntType | Integer type for the result |
Example usage:
int outcome = weighted_die(rng);
std::vector<double> rarities = {50.0, 30.0, 15.0, 4.0, 1.0};
int rarity_tier = item_rarity(rng);
int item_type = loot(rng);
auto weight_fn = [](double x) { return x * x; };
int index = custom(rng);
Platform-independent discrete distribution with arbitrary probabilities.
Definition PRNGDistribution.hpp:3542
Pseudo-random number generator for procedural generation.
Definition PRNG.hpp:48
template class INFINITY_API_PUBLIC DiscreteDistribution< int >
Definition PRNGDistribution.cpp:61
- Note
- Weights are automatically normalized to probabilities summing to 1.
-
Returns integers in [0, n) where n is the number of weights.
-
If all weights are zero, falls back to uniform distribution.
-
Uses binary search on cumulative probabilities for O(log n) generation.