All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
Aux::Random Namespace Reference

Provides several functions for random-numbers. More...

Functions

void setSeed (uint64_t seed, bool useThreadId)
 Sets the random seed that is used globally. More...
 
uint64_t getSeed ()
 
std::mt19937_64 & getURNG ()
 
uint64_t integer ()
 
uint64_t integer (uint64_t upperBound)
 
uint64_t integer (uint64_t lowerBound, uint64_t upperBound)
 
double real ()
 
double real (double upperBound)
 
double real (double lowerBound, double upperBound)
 
double probability ()
 
std::size_t index (std::size_t max)
 
template<typename Container >
Container::const_reference choice (const Container &container)
 
template<typename Element >
const Element & weightedChoice (const std::vector< std::pair< Element, double >> &weightedElements)
 

Detailed Description

Provides several functions for random-numbers.

All functions are guaranteed to be thread-safe if and only if at least GCC 4.8 is used

Function Documentation

template<typename Container >
Container::const_reference Aux::Random::choice ( const Container &  container)
Returns
an integer distributed binomially
Parameters
nnumber of trials
psuccess probability
Returns
a uniform random choice from an indexable container of elements.
uint64_t Aux::Random::getSeed ( )
Returns
a high-quality random seed for an URNG.
std::mt19937_64 & Aux::Random::getURNG ( )
Returns
a reference to a seeded URNG that is thread_local iff GCC 4.8 or later is used.
std::size_t Aux::Random::index ( std::size_t  max)
Returns
a size_t in the range [0, max - 1] that can for example be used to access a random element of a container.
uint64_t Aux::Random::integer ( )
Returns
an integer distributed uniformly in an inclusive range;
Parameters
upperBoundthe upper bound, default = UNINT64_T_MAX
lowerBoundthe lower bound, default = 0
uint64_t Aux::Random::integer ( uint64_t  upperBound)
uint64_t Aux::Random::integer ( uint64_t  lowerBound,
uint64_t  upperBound 
)
double Aux::Random::probability ( )
Returns
a double distributed uniformly in the range [0, 1]
Note
this differs from real() in returning a value in a closed instead of a half-open range.
double Aux::Random::real ( )
Returns
a double distributed uniformly in a half-open range: [lowerBound, upperBound)
Parameters
upperBounddefault = 1.0
lowerBounddefault = 0.0
double Aux::Random::real ( double  upperBound)
double Aux::Random::real ( double  lowerBound,
double  upperBound 
)
void Aux::Random::setSeed ( uint64_t  seed,
bool  useThreadId 
)

Sets the random seed that is used globally.

Parameters
seedThe seed value
useThreadIdIf the thread id shall be added to the seed value
template<typename Element >
const Element& Aux::Random::weightedChoice ( const std::vector< std::pair< Element, double >> &  weightedElements)
Returns
a weighted random choice from a vector of elements with given weights.