|
Player12
An open source football management simulator
|
Deterministic, portable pseudo random generator (xoshiro256**). More...
#include <world_rng.h>
Public Types | |
| using | result_type = std::uint64_t |
Public Member Functions | |
| WorldRng (std::uint64_t seed) | |
| result_type | operator() () |
| std::uint64_t | next () |
| double | uniform01 () |
| float | uniform (float lo, float hi) |
| int | uniformInt (int lo, int hi) |
| float | normal (float mean, float stddev) |
| float | lognormal (float median, float sigma) |
| bool | chance (double p) |
| std::size_t | weightedIndex (std::span< const float > weights) |
| template<typename T > | |
| void | shuffle (std::span< T > values) |
Static Public Member Functions | |
| static WorldRng | stream (std::uint64_t world_seed, RngDomain domain, std::uint64_t key_a=0, std::uint64_t key_b=0) |
| static double | hashUniform (std::uint64_t world_seed, RngDomain domain, std::uint64_t key_a, std::uint64_t key_b=0) |
| static constexpr result_type | min () |
| static constexpr result_type | max () |
Private Attributes | |
| std::array< std::uint64_t, 4 > | state {} |
Deterministic, portable pseudo random generator (xoshiro256**).
All distributions are implemented here instead of using <random> distributions, whose algorithms differ between standard libraries. The same seed therefore produces the same world on every platform.
| using WorldRng::result_type = std::uint64_t |
|
explicit |
Seeds the four state words from seed through splitmix64.
| bool WorldRng::chance | ( | double | p | ) |
Bernoulli trial with probability p.
|
static |
Single uniform draw in [0, 1) without constructing a stream.
| float WorldRng::lognormal | ( | float | median, |
| float | sigma | ||
| ) |
Lognormal value with the given median and log-space sigma.
|
inlinestaticconstexpr |
|
inlinestaticconstexpr |
| std::uint64_t WorldRng::next | ( | ) |
Next raw 64-bit value.
| float WorldRng::normal | ( | float | mean, |
| float | stddev | ||
| ) |
Normally distributed value (Box-Muller over PortableMath).
|
inline |
|
inline |
Fisher-Yates shuffle with this generator.
|
static |
Creates the stream for domain keyed by up to two stable values.
| float WorldRng::uniform | ( | float | lo, |
| float | hi | ||
| ) |
Uniform float in [lo, hi).
| double WorldRng::uniform01 | ( | ) |
Uniform double in [0, 1).
| int WorldRng::uniformInt | ( | int | lo, |
| int | hi | ||
| ) |
Uniform integer in [lo, hi] (inclusive, unbiased).
| std::size_t WorldRng::weightedIndex | ( | std::span< const float > | weights | ) |
Index drawn proportionally to non-negative weights.
|
private |