GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::randomness Namespace Reference

Classes

class  SplitMix64Engine
 Implementation of the SplitMix64 pseudorandom number generator that provides the API required for a standard uniform random bit generator, so that it can be plugged into any of the random number distributions provided by the standard library. More...
class  Xoroshiro128PlusPlusEngine
 Implementation of the xoroshiro128++ pseudorandom number generator that provides the API required for a standard uniform random bit generator, so that it can be plugged into any of the random number distributions provided by the standard library. More...

Typedefs

using NonDeterministicRandomEngine = std::random_device
 Uniformly-destributed random number generator that provides non-deterministic random numbers if supported by the host system.
using DefaultRandomEngine = Xoroshiro128PlusPlusEngine
 Default pseudorandom number generator.
template<typename Integer>
using UniformIntegerDistribution = std::uniform_int_distribution<Integer>
 Random number distribution that produces integer values uniformly distributed on the closed interval [a, b].
template<typename Float>
using UniformRealDistribution = std::uniform_real_distribution<Float>
 Random number distribution that produces floating-point values uniformly distributed on the half-open interval [a, b).
using BernoulliDistribution = std::bernoulli_distribution
 Random number distribution that produces boolean values with probability p of being true.
template<typename Integer>
using BinomialDistribution = std::binomial_distribution<Integer>
 Random number distribution that produces non-negative integer values that correspond to the number of true values in a sequence of t boolean tests, each with probability p of being true.
template<typename Integer>
using NegativeBinomialDistribution = std::negative_binomial_distribution<Integer>
 Random number distribution that produces non-negative integer values that correspond to the number of false values before exactly k true values occur in a sequence of boolean tests, each with probability p of being true.
template<typename Integer>
using GeometricDistribution = std::geometric_distribution<Integer>
 Random number distribution that produces non-negative integer values that correspond to the number of false values before a true value occurs in a sequence of boolean tests, each with probability p of being true.
template<typename Integer>
using PoissonDistribution = std::poisson_distribution<Integer>
 Random number distribution that produces non-negative integer values that correspond to the number of occurences of a random event where the expected average number of occurences is μ in the same interval under the same conditions.
template<typename Float>
using ExponentialDistribution = std::exponential_distribution<Float>
 Random number distribution that produces non-negative floating-point values that correspond to the time/distance until the next random event if random events occur at a constant average rate λ per unit of time/distance.
template<typename Float>
using NormalDistribution = std::normal_distribution<Float>
 Random number distribution that produces floating-point values according to a Normal/Gaussian distribution with mean μ and standard deviation σ.
template<typename Integer>
using DiscreteDistribution = std::discrete_distribution<Integer>
 Random number distribution that, given a list of weights w, produces integer values in the interval [0, w.size() - 1] with each integer i having probability w[i] / sum(w) of being selected.

Functions

template<floating_point T, size_t EntropyBits = std::numeric_limits<T>::digits>
T generateCanonical (auto &generator)
 Generate a random floating-point number uniformly distributed on the half-open interval [0, 1).

Typedef Documentation

◆ NonDeterministicRandomEngine

Uniformly-destributed random number generator that provides non-deterministic random numbers if supported by the host system.

Warning
The performance of this engine may sharply degrade once the available entropy is exhausted. Therefore, it should mainly be used to seed a pseudorandom number generator such as DefaultRandomEngine.

◆ DefaultRandomEngine

Default pseudorandom number generator.

Note
This type may be different from std::default_random_engine.
Warning
This engine is not guaranteed to produce cryptographcially secure randomness and should therefore not be used in situations that require a CSPRNG.

◆ UniformIntegerDistribution

template<typename Integer>
using grem::randomness::UniformIntegerDistribution = std::uniform_int_distribution<Integer>

Random number distribution that produces integer values uniformly distributed on the closed interval [a, b].

Template Parameters
Integerinteger type to generate. Must be one of the following types:
  • short
  • int
  • long
  • long long
  • unsigned short
  • unsigned
  • unsigned long
  • unsigned long long

◆ UniformRealDistribution

template<typename Float>
using grem::randomness::UniformRealDistribution = std::uniform_real_distribution<Float>

Random number distribution that produces floating-point values uniformly distributed on the half-open interval [a, b).

Template Parameters
Floatfloating-point type to generate. Must be one of the following types:
  • float
  • double
  • long double
Warning
Most existing implementations have a bug where they may occasionally return b, despite the interval being defined as half-open.

◆ BernoulliDistribution

using grem::randomness::BernoulliDistribution = std::bernoulli_distribution

Random number distribution that produces boolean values with probability p of being true.

◆ BinomialDistribution

template<typename Integer>
using grem::randomness::BinomialDistribution = std::binomial_distribution<Integer>

Random number distribution that produces non-negative integer values that correspond to the number of true values in a sequence of t boolean tests, each with probability p of being true.

Template Parameters
Integerinteger type to generate. Must be one of the following types:
  • short
  • int
  • long
  • long long
  • unsigned short
  • unsigned
  • unsigned long
  • unsigned long long

◆ NegativeBinomialDistribution

template<typename Integer>
using grem::randomness::NegativeBinomialDistribution = std::negative_binomial_distribution<Integer>

Random number distribution that produces non-negative integer values that correspond to the number of false values before exactly k true values occur in a sequence of boolean tests, each with probability p of being true.

Template Parameters
Integerinteger type to generate. Must be one of the following types:
  • short
  • int
  • long
  • long long
  • unsigned short
  • unsigned
  • unsigned long
  • unsigned long long

◆ GeometricDistribution

template<typename Integer>
using grem::randomness::GeometricDistribution = std::geometric_distribution<Integer>

Random number distribution that produces non-negative integer values that correspond to the number of false values before a true value occurs in a sequence of boolean tests, each with probability p of being true.

This distribution is equivalent to NegativeBinomialDistribution with k = 1, and is the integer counterpart of ExponentialDistribution.

Template Parameters
Integerinteger type to generate. Must be one of the following types:
  • short
  • int
  • long
  • long long
  • unsigned short
  • unsigned
  • unsigned long
  • unsigned long long

◆ PoissonDistribution

template<typename Integer>
using grem::randomness::PoissonDistribution = std::poisson_distribution<Integer>

Random number distribution that produces non-negative integer values that correspond to the number of occurences of a random event where the expected average number of occurences is μ in the same interval under the same conditions.

Template Parameters
Integerinteger type to generate. Must be one of the following types:
  • short
  • int
  • long
  • long long
  • unsigned short
  • unsigned
  • unsigned long
  • unsigned long long

◆ ExponentialDistribution

template<typename Float>
using grem::randomness::ExponentialDistribution = std::exponential_distribution<Float>

Random number distribution that produces non-negative floating-point values that correspond to the time/distance until the next random event if random events occur at a constant average rate λ per unit of time/distance.

This distribution is the floating-point counterpart of GeometricDistribution.

Template Parameters
Floatfloating-point type to generate. Must be one of the following types:
  • float
  • double
  • long double

◆ NormalDistribution

template<typename Float>
using grem::randomness::NormalDistribution = std::normal_distribution<Float>

Random number distribution that produces floating-point values according to a Normal/Gaussian distribution with mean μ and standard deviation σ.

Template Parameters
Floatfloating-point type to generate. Must be one of the following types:
  • float
  • double
  • long double

◆ DiscreteDistribution

template<typename Integer>
using grem::randomness::DiscreteDistribution = std::discrete_distribution<Integer>

Random number distribution that, given a list of weights w, produces integer values in the interval [0, w.size() - 1] with each integer i having probability w[i] / sum(w) of being selected.

Template Parameters
Integerinteger type to generate. Must be one of the following types:
  • short
  • int
  • long
  • long long
  • unsigned short
  • unsigned
  • unsigned long
  • unsigned long long

Function Documentation

◆ generateCanonical()

template<floating_point T, size_t EntropyBits = std::numeric_limits<T>::digits>
T grem::randomness::generateCanonical ( auto & generator)
inlinenodiscard

Generate a random floating-point number uniformly distributed on the half-open interval [0, 1).

Template Parameters
Tfloating-point number type to generate.
EntropyBitsnumber of bits of entropy to acquire when generating the result.
Parameters
generatoruniform random bit generator to acquire entropy from.
Returns
a value in the range [0, 1).
Warning
Most existing implementations have a bug where they may occasionally return 1, despite the interval being defined as half-open.