cxxomfort  rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
Classes | Namespaces | Typedefs | Functions
library/random.hpp File Reference

Classes

struct  splitmix64
 Pseudo-RNG generator. More...
 

Namespaces

 cxxomfort
 Namespace of the cxxomfort library.
 
 cxxomfort::library
 Supplements to backports and other utilities.
 

Typedefs

typedef std::linear_congruential_engine< uint32_t, 1664525, 1013904223, 0 > lcg_numerical_recipes_rand
 LCG as it appears in Numerical Recipes. More...
 
typedef std::linear_congruential_engine< uint64_t, 6364136223846793005, 1, 0 > musl_rand
 LCG specification as it appears in MUSL Libc.This is an alternative to eg.: std::minstd and other linear congruential engines. More...
 
typedef std::linear_congruential_engine< uint_least64_t, 0x00000005deece66dULL, 0xb, 0x0001000000000000ULL > rand48
 LCG specification as it appears in FreeBSD.This is an alternative to eg.: std::minstd and other linear congruential engines. More...
 
typedef std::linear_congruential_engine< unsigned int, 0, 4, 0 > xkcd221_rand
 LCG specification following Randall Munroe's xkcd #221. More...
 

Functions

template<typename Gen , typename Integer >
Integer uniform_choose (Gen &g, Integer a, Integer b)
 Given a generator g , generate and choose an integer in the range [a, b]. More...
 
template<typename Gen , typename Iterator >
Iterator uniform_pick (Gen &g, Iterator ini, Iterator fin)
 Choose one in a sequence of values [ini,fin). More...
 

Detailed Description

<random>:

Typedef Documentation

◆ lcg_numerical_recipes_rand

lcg_numerical_recipes_rand

LCG as it appears in Numerical Recipes.

See also
https://en.wikipedia.org/wiki/Numerical_Recipes

This is an alternative to eg.: std::minstd and other linear congruential engines, using as parameters to the generator the parameters specified in Numerical Recipes .

When invoked with operator() returns a uint32_t value.

◆ musl_rand

musl_rand

LCG specification as it appears in MUSL Libc.This is an alternative to eg.: std::minstd and other linear congruential engines.

When invoked with operator() returns a uint64_t value.

◆ rand48

rand48

LCG specification as it appears in FreeBSD.This is an alternative to eg.: std::minstd and other linear congruential engines.

When invoked with operator() returns a uint64_t value within a range that uses the first (lowest) 48 bits.

◆ xkcd221_rand

xkcd221_rand

LCG specification following Randall Munroe's xkcd #221.

See also
https://xkcd.com/221/

This is an alternative to eg.: std::minstd and other linear congruential engines.

When invoked with operator() returns a unsigned value. The generator is equivalent to the following hand-written code:

struct xkcd221_r {
constexpr unsigned int () const noexcept {
return 4; // chosen by fair dice roll, guaranteed to be random
}
};

Function Documentation

◆ uniform_choose()

Integer cxxomfort::library::random::uniform_choose ( Gen &  g,
Integer  a,
Integer  b 
)

Given a generator g , generate and choose an integer in the range [a, b].

Parameters
gA generator object (lvalue).
Returns
An Integer value.
Precondition
Integer is a C++ integer type.

Referenced by cxxomfort::library::random::uniform_choose().

◆ uniform_pick()

Iterator cxxomfort::library::random::uniform_pick ( Gen &  g,
Iterator  ini,
Iterator  fin 
)

Choose one in a sequence of values [ini,fin).

Parameters
ini,finA sequence's begin and end iterators.
Returns
An iterator in the range [ini,fin).

This function uses uniform_choose() on the passed generator g to uniformly pick one iterator within the desired range.

Referenced by cxxomfort::library::random::uniform_pick().