Player12
An open source football management simulator
Loading...
Searching...
No Matches
PortableRandom Namespace Reference

Concepts

concept  FullRangeEngine
 

Functions

template<FullRangeEngine Engine>
std::uint32_t bits32 (Engine &engine)
 
template<FullRangeEngine Engine>
std::uint64_t bits64 (Engine &engine)
 
float unitFloat (std::uint32_t bits)
 
double unitDouble (std::uint64_t bits)
 
float lerp (float lo, float hi, float unit)
 
double lerp (double lo, double hi, double unit)
 
double affine (double offset, double scale, double value)
 
double standardNormal (double u1, double u2)
 
int poissonFromUnit (double unit, double mean)
 
template<FullRangeEngine Engine>
float uniformReal (Engine &engine, float lo, float hi)
 
template<FullRangeEngine Engine>
double uniformReal (Engine &engine, double lo, double hi)
 
template<FullRangeEngine Engine>
std::uint64_t below (Engine &engine, std::uint64_t count)
 
template<FullRangeEngine Engine>
int uniformInt (Engine &engine, int lo, int hi)
 
template<FullRangeEngine Engine>
double normal (Engine &engine, double mean, double stddev)
 
template<FullRangeEngine Engine>
int poisson (Engine &engine, double mean)
 

Detailed Description

Distributions over any standard 32- or 64-bit generator (std::mt19937, std::mt19937_64), with the same results on every platform. Use these instead of the <random> distributions, whose algorithms are left to the standard library. The arithmetic lives out of line in world_rng.cpp.

Function Documentation

◆ affine()

double PortableRandom::affine ( double  offset,
double  scale,
double  value 
)
private

offset + value * scale, never contracted to a fused op.

◆ below()

template<FullRangeEngine Engine>
std::uint64_t PortableRandom::below ( Engine &  engine,
std::uint64_t  count 
)
private

Uniform integer in [0, count) without modulo bias; 0 if count is 0.

◆ bits32()

template<FullRangeEngine Engine>
std::uint32_t PortableRandom::bits32 ( Engine &  engine)
private

32 random bits (the high half of a 64-bit engine's output).

◆ bits64()

template<FullRangeEngine Engine>
std::uint64_t PortableRandom::bits64 ( Engine &  engine)
private

64 random bits (two draws of a 32-bit engine, the first one high).

◆ lerp() [1/2]

double PortableRandom::lerp ( double  lo,
double  hi,
double  unit 
)
private

◆ lerp() [2/2]

float PortableRandom::lerp ( float  lo,
float  hi,
float  unit 
)
private

lo + unit * (hi - lo), never contracted to a fused op.

◆ normal()

template<FullRangeEngine Engine>
double PortableRandom::normal ( Engine &  engine,
double  mean,
double  stddev 
)
private

Normally distributed value.

◆ poisson()

template<FullRangeEngine Engine>
int PortableRandom::poisson ( Engine &  engine,
double  mean 
)
private

Poisson distributed count of mean mean (>= 0).

◆ poissonFromUnit()

int PortableRandom::poissonFromUnit ( double  unit,
double  mean 
)
private

Poisson value of mean mean (<= 64) by inversion of unit.

◆ standardNormal()

double PortableRandom::standardNormal ( double  u1,
double  u2 
)
private

Standard normal value from two uniforms (Box-Muller); u1 in (0, 1].

◆ uniformInt()

template<FullRangeEngine Engine>
int PortableRandom::uniformInt ( Engine &  engine,
int  lo,
int  hi 
)
private

Uniform integer in [lo, hi] (inclusive).

◆ uniformReal() [1/2]

template<FullRangeEngine Engine>
double PortableRandom::uniformReal ( Engine &  engine,
double  lo,
double  hi 
)
private

Uniform double in [lo, hi).

◆ uniformReal() [2/2]

template<FullRangeEngine Engine>
float PortableRandom::uniformReal ( Engine &  engine,
float  lo,
float  hi 
)
private

Uniform float in [lo, hi).

◆ unitDouble()

double PortableRandom::unitDouble ( std::uint64_t  bits)
private

Double in [0, 1) from the top 53 of bits.

◆ unitFloat()

float PortableRandom::unitFloat ( std::uint32_t  bits)
private

Float in [0, 1) from the top 24 of bits.