random

Namespaces

Structs

normal

template<typename T = double>
struct normal

Box-Muller random normal number generator.

Ensures similar numbers generated on different operating systems.

Public Functions

inline normal(const T mu, const T sigma)
inline normal()
template<typename G>
inline T operator()(G &gen)

Generate a standard normal random number with mean 0 and std dev 1.

Template Parameters:

G – the type of the generator

Parameters:

gen – the generator instance

Returns:

T the random number

Public Members

T mu
T sigma
T r1 = {}

the second number of the last pair, which the next call returns (per object, not shared)

T r2 = {}
bool generate = true

uniform

template<typename T = double>
struct uniform

Public Functions

template<typename G>
inline T operator()(G &gen)

Generate a random uniform number in the closed interval [-1, 1].

Template Parameters:

G – the type of the generator

Parameters:

gen – the generator instance

Returns:

T the random number

Functions

GENERATOR

Warning

doxygenfunction: Unable to resolve function “ioh::common::random::GENERATOR” with arguments “None”. Candidate function could not be parsed. Parsing error is Error when parsing function declaration. If the function has no return type: Error in declarator or parameters-and-qualifiers Invalid C++ declaration: Expected identifier in nested name, got keyword: thread_local [error at 12] thread_local std::mt19937 GENERATOR (std::random_device{}()) ————^ If the function has a return type: Invalid C++ declaration: Expected identifier in nested name, got keyword: thread_local [error at 12] thread_local std::mt19937 GENERATOR (std::random_device{}()) ————^

doubles

inline std::vector<double> ioh::common::random::doubles(const unsigned int n, const double min = 0.0, const double max = 1.0)

This function returns a vector random uniform doubles within the range [min, max].

Parameters:
  • n – The size of the vector

  • min – the minimal boundary

  • max – the maximum boundary

Returns:

vector of uniform random doubles

integer

inline int ioh::common::random::integer(const int min = std::numeric_limits<int>::min(), const int max = std::numeric_limits<int>::max())

This function returns a random uniform integer within the range [min, max].

Parameters:
  • min – the minimal boundary

  • max – the maximum boundary

Returns:

a random uniform integer

integers

inline std::vector<int> ioh::common::random::integers(const unsigned int n, const int min = std::numeric_limits<int>::min(), const int max = std::numeric_limits<int>::max())

This function returns a vector of random uniform integer within the range [min, max] of size n.

Parameters:
  • n – The size of the vector

  • min – The minimal boundary

  • max – The maximum boundary

Returns:

A vector of uniform random integers

lcg_rand

inline long ioh::common::random::lcg_rand(long seed)

Linear congruential generator using a given seed.

Used to generate uniform random numbers.

Parameters:

seed – Random seed

Returns:

A new seed

real

inline double ioh::common::random::real(const double min = 0.0, const double max = 1.0)

This function returns a random uniform double within the range [min, max].

Parameters:
  • min – the minimal boundary

  • max – the maximum boundary

Returns:

a random double

seed

inline void ioh::common::random::seed(const unsigned int seed)

Seed the random number generator of the calling thread.

This is a std::mt19937 rng

Variables

RD

std::random_device ioh::common::random::RD

Global random device.