SyTen
syten::Random Namespace Reference

The random number generation engine generation subsystem. More...

Typedefs

using Engine = std::mt19937_64
 The engine type returned by genEngine() below. More...
 
using Result = typename Engine::result_type
 The type of the results generated by engines from genEngine() as well as the seed type used to initialise the engine-generation engine. More...
 

Functions

void disableReproducible ()
 Sets the global seed to zero, causing non-reproducible generation of random number engines by genEngine(). More...
 
Engine genEngine ()
 Returns a random number generation engine. More...
 
Result genValue ()
 Generates a single value from the internal LCG, mainly useful for debugging. More...
 
Result const & getSeed ()
 Returns the seed used by the internal LCG. More...
 
Result initReproducible (Result const seed_=0)
 Initialises the global generating random number engine. More...
 
bool isReproducible ()
 Returns true if the global seed is non-zero and no threading is used. More...
 

Variables

std::linear_congruential_engine< Result, 6364136223846793005ULL, 1442695040888963407ULL, 18446744073709551615ULL > engine {std::random_device()()}
 Engine used to generate seeds for genEngine() below. More...
 
std::mutex mtx_engine
 Mutex protecting genEngine (and engine) below if seed is non-zero. More...
 
Result seed {0}
 global seed, if zero, none was set and genEngine() is non-deterministic More...
 

Detailed Description

The random number generation engine generation subsystem.

The idea is as follows:

If Random::seed is zero, it acquires a non-deterministic seed to initialise the engine it returns. If Random::seed is non-zero, it locks a mutex and uses the next result from a global random number generation engine to initialise the new engine. It then returns that new engine.

  • Random:seed is initialised by a call to Random::initReproducible(), either by the argument to that call or from a non-deterministic hardware source. initReproducible() returns that seed.
  • Random::isReproducible() returns true if the random subsystem is in a somewhat deterministic state right now. It cannot check what you did before or what you’re going to do later, only that
  • a global seed is set, i.e. a global engine is generating the seeds for the individual engines returned by genEngine()
  • and all Threading::*Num values are set to 1, i.e. no threading takes place.
  • Random::disableReproducible() sets Random::seed to zero. Afterwards, non-deterministic random values will be used for initialisation of the engines returned by genEngine().