4#ifndef GREM_CORE_RANDOMNESS_HPP
5#define GREM_CORE_RANDOMNESS_HPP
59 state += 0x9E3779B97F4A7C15ull;
61 z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ull;
62 z = (z ^ (z >> 27)) * 0x94D049BB133111EBull;
66 constexpr void discard(
unsigned long long z)
noexcept {
73 return state == other.state;
76 template <
typename CharT,
typename Traits>
78 return stream << engine.state;
81 template <
typename CharT,
typename Traits>
83 return stream >> engine.state;
131 setState({stateGenerator(), stateGenerator()});
135 const uint64_t s0 = state[0];
136 uint64_t s1 = state[1];
144 constexpr void discard(
unsigned long long z)
noexcept {
153 constexpr void jump() noexcept {
156 for (
const uint64_t c : {0x2BD7A6A6E99C2DDCull, 0x0992CCAF6A6FCA05ull}) {
157 for (
int b = 0; b < 64; ++b) {
158 if ((c & (uint64_t{1} << b)) != 0) {
175 for (
const uint64_t c : {0x360FD5F2CF8D5D99ull, 0x9C6E6877736C46E3ull}) {
176 for (
int b = 0; b < 64; ++b) {
177 if ((c & (uint64_t{1} << b)) != 0) {
215 return state == other.state;
218 template <
typename CharT,
typename Traits>
220 return stream << engine.state[0] <<
' ' << engine.state[1];
223 template <
typename CharT,
typename Traits>
225 return stream >> engine.state[0] >> engine.state[1];
267template <
typename Integer>
283template <
typename Float>
307template <
typename Integer>
325template <
typename Integer>
346template <
typename Integer>
365template <
typename Integer>
381template <
typename Float>
394template <
typename Float>
412template <
typename Integer>
430template <floating_point T, size_t EntropyBits = std::numeric_limits<T>::digits>
432 return std::generate_canonical<T, EntropyBits>(generator);
Implementation of the SplitMix64 pseudorandom number generator that provides the API required for a s...
Definition randomness.hpp:34
constexpr SplitMix64Engine() noexcept
Definition randomness.hpp:48
constexpr void discard(unsigned long long z) noexcept
Definition randomness.hpp:66
static constexpr result_type min()
Definition randomness.hpp:40
constexpr bool operator==(const SplitMix64Engine &other) const noexcept
Definition randomness.hpp:72
uint64_t result_type
Definition randomness.hpp:36
static constexpr result_type max()
Definition randomness.hpp:44
static constexpr result_type default_seed
Definition randomness.hpp:38
constexpr result_type operator()() noexcept
Definition randomness.hpp:58
constexpr SplitMix64Engine(result_type seedValue) noexcept
Definition randomness.hpp:51
friend std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &stream, SplitMix64Engine &engine)
Definition randomness.hpp:82
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &stream, const SplitMix64Engine &engine)
Definition randomness.hpp:77
constexpr void seed(result_type seedValue=default_seed) noexcept
Definition randomness.hpp:54
Implementation of the xoroshiro128++ pseudorandom number generator that provides the API required for...
Definition randomness.hpp:104
friend std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &stream, Xoroshiro128PlusPlusEngine &engine)
Definition randomness.hpp:224
constexpr State getState() const noexcept
Get the value representation of the internal state.
Definition randomness.hpp:210
constexpr Xoroshiro128PlusPlusEngine() noexcept
Definition randomness.hpp:119
constexpr bool operator==(const Xoroshiro128PlusPlusEngine &other) const noexcept
Definition randomness.hpp:214
static constexpr result_type max()
Definition randomness.hpp:115
uint64_t result_type
Definition randomness.hpp:106
Array< uint64_t, 2 > State
Definition randomness.hpp:107
static constexpr result_type default_seed
Definition randomness.hpp:109
constexpr void longJump() noexcept
Advance the internal state 2^96 times.
Definition randomness.hpp:172
constexpr result_type operator()() noexcept
Definition randomness.hpp:134
static constexpr result_type min()
Definition randomness.hpp:111
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &stream, const Xoroshiro128PlusPlusEngine &engine)
Definition randomness.hpp:219
constexpr void seed(result_type seedValue=default_seed) noexcept
Definition randomness.hpp:129
constexpr void jump() noexcept
Advance the internal state 2^64 times.
Definition randomness.hpp:153
constexpr void discard(unsigned long long z) noexcept
Definition randomness.hpp:144
constexpr Xoroshiro128PlusPlusEngine(result_type seedValue) noexcept
Definition randomness.hpp:122
constexpr void setState(const State &newState) noexcept
Set the value representation of the internal state.
Definition randomness.hpp:197
constexpr Xoroshiro128PlusPlusEngine(const State &state) noexcept
Definition randomness.hpp:126
Definition aliases.hpp:19
T generateCanonical(auto &generator)
Generate a random floating-point number uniformly distributed on the half-open interval [0,...
Definition randomness.hpp:431
std::random_device NonDeterministicRandomEngine
Uniformly-destributed random number generator that provides non-deterministic random numbers if suppo...
Definition randomness.hpp:240
std::uniform_real_distribution< Float > UniformRealDistribution
Random number distribution that produces floating-point values uniformly distributed on the half-open...
Definition randomness.hpp:284
std::binomial_distribution< Integer > BinomialDistribution
Random number distribution that produces non-negative integer values that correspond to the number of...
Definition randomness.hpp:308
std::exponential_distribution< Float > ExponentialDistribution
Random number distribution that produces non-negative floating-point values that correspond to the ti...
Definition randomness.hpp:382
std::normal_distribution< Float > NormalDistribution
Random number distribution that produces floating-point values according to a Normal/Gaussian distrib...
Definition randomness.hpp:395
std::negative_binomial_distribution< Integer > NegativeBinomialDistribution
Random number distribution that produces non-negative integer values that correspond to the number of...
Definition randomness.hpp:326
std::geometric_distribution< Integer > GeometricDistribution
Random number distribution that produces non-negative integer values that correspond to the number of...
Definition randomness.hpp:347
Xoroshiro128PlusPlusEngine DefaultRandomEngine
Default pseudorandom number generator.
Definition randomness.hpp:251
std::poisson_distribution< Integer > PoissonDistribution
Random number distribution that produces non-negative integer values that correspond to the number of...
Definition randomness.hpp:366
std::discrete_distribution< Integer > DiscreteDistribution
Random number distribution that, given a list of weights w, produces integer values in the interval [...
Definition randomness.hpp:413
std::uniform_int_distribution< Integer > UniformIntegerDistribution
Random number distribution that produces integer values uniformly distributed on the closed interval ...
Definition randomness.hpp:268
std::bernoulli_distribution BernoulliDistribution
Random number distribution that produces boolean values with probability p of being true.
Definition randomness.hpp:290
GREM_ALWAYS_INLINE constexpr UnsignedInteger rotateBitsLeft(UnsignedInteger value, int shift) noexcept
Get the result of bitwise left-rotating a value by a number of bits.
Definition fundamentals.hpp:645
static constexpr T MAX
Definition fundamentals.hpp:29