Ocean
Ocean::RandomI Class Reference

This class provides base random functions and several random functions for integer data types. More...

Inheritance diagram for Ocean::RandomI:

Static Public Member Functions

static void initialize ()
 Initializes the standard random generator for this thread with a time-based seed value. More...
 
static void initialize (const unsigned int value)
 Initializes the standard random generator for this thread with a user-defined seed value. More...
 
static uint32_t random32 ()
 Returns one random integer number with range [0x00000000, 0xFFFFFFFF]. More...
 
static uint32_t random32 (RandomGenerator &randomGenerator)
 Returns one random integer number with range [0x00000000, 0xFFFFFFFF] using an explicit random generator. More...
 
static uint64_t random64 ()
 Returns one random integer number with range [0x00000000 00000000, 0xFFFFFFFF FFFFFFFF]. More...
 
static uint64_t random64 (RandomGenerator &randomGenerator)
 Returns one random integer number with range [0x00000000 00000000, 0xFFFFFFFF FFFFFFFF] using an explicit random generator. More...
 
static unsigned int random (const unsigned int maxValue)
 Returns one random integer value with specified maximum value. More...
 
static unsigned int random (RandomGenerator &randomGenerator, const unsigned int maxValue)
 Returns one random integer value with specified maximum value using an explicit random generator. More...
 
static int random (const int lower, const int upper)
 Returns one random integer value within a specific range. More...
 
static unsigned int random (const unsigned int lower, const unsigned int upper)
 Returns one random integer value within a specific range. More...
 
static int random (RandomGenerator &randomGenerator, const int lower, const int upper)
 Returns one random integer value within a specific range using an explicit random generator. More...
 
static unsigned int random (RandomGenerator &randomGenerator, const unsigned int lower, const unsigned int upper)
 Returns one random integer value within a specific range using an explicit random generator. More...
 
static void random (const unsigned int maxValue, unsigned int &first, unsigned int &second)
 Returns two different random integer values with specified maximum value. More...
 
static void random (RandomGenerator &randomGenerator, const unsigned int maxValue, unsigned int &first, unsigned int &second)
 Returns two different random integer values with specified maximum value using an explicit random generator. More...
 
static void random (const unsigned int maxValue, unsigned int &first, unsigned int &second, unsigned int &third)
 Returns three different random integer values with specified maximum value. More...
 
static void random (RandomGenerator &randomGenerator, const unsigned int maxValue, unsigned int &first, unsigned int &second, unsigned int &third)
 Returns three different random integer values with specified maximum value using an explicit random generator. More...
 
static bool boolean ()
 Returns a random bool value. More...
 
static bool boolean (RandomGenerator &randomGenerator)
 Returns a random bool value. More...
 
template<typename T >
static T random (const std::vector< T > &elements)
 Randomly returns one element from a given vector. More...
 
template<typename T >
static T random (const std::initializer_list< T > &elements)
 Randomly returns one element from a given initializer list. More...
 
template<typename T >
static T random (RandomGenerator &randomGenerator, const std::vector< T > &elements)
 Randomly returns one element from a given vector. More...
 
template<typename T >
static T random (RandomGenerator &randomGenerator, const std::initializer_list< T > &elements)
 Randomly returns one element from a given initializer list. More...
 
static unsigned int timeBasedSeed ()
 Returns a seed value based on the current time. More...
 

Static Protected Member Functions

static constexpr unsigned int randMax ()
 Returns the maximal random value of the default random number generator. More...
 

Detailed Description

This class provides base random functions and several random functions for integer data types.

Beware: All function must not be used without a initialize() call for each thread!
The performance of the random number generator may be very poor in multi-threaded environments.
Therefore, use an instance of the RandomGenerator class in functions which are invoked in parallel.

See also
initialize().
RandomGenerator.

Member Function Documentation

◆ boolean() [1/2]

bool Ocean::RandomI::boolean ( )
inlinestatic

Returns a random bool value.

Returns
True or False

◆ boolean() [2/2]

bool Ocean::RandomI::boolean ( RandomGenerator randomGenerator)
inlinestatic

Returns a random bool value.

Parameters
randomGeneratorThe random generator to be used
Returns
True or False

◆ initialize() [1/2]

static void Ocean::RandomI::initialize ( )
static

Initializes the standard random generator for this thread with a time-based seed value.

Please ensure that you have called RandomI::initialize() just once (for each individual thread) before using any other function of this class.
You also my use a user-defined seed value e.g., to be able to reproduce the behavior of a system using random numbers, just use the second initialize function in this case.

◆ initialize() [2/2]

static void Ocean::RandomI::initialize ( const unsigned int  value)
static

Initializes the standard random generator for this thread with a user-defined seed value.

In contrast to the time-based initialization function, this function here can be invoked as often as necessary for any thread at any time.

Parameters
valueInitialization value to be used, with range [0, infinity)

◆ randMax()

constexpr unsigned int Ocean::RandomI::randMax ( )
staticconstexprprotected

Returns the maximal random value of the default random number generator.

Returns
Maximal random value of the default generator

◆ random() [1/14]

static int Ocean::RandomI::random ( const int  lower,
const int  upper 
)
static

Returns one random integer value within a specific range.

Parameters
lowerThe lower border, with range (-infinity, infinity)
upperThe upper border, with range [lower, infinity)
Returns
Random integer number, with range [lower, lower + 2147483647]

◆ random() [2/14]

template<typename T >
T Ocean::RandomI::random ( const std::initializer_list< T > &  elements)
static

Randomly returns one element from a given initializer list.

Parameters
elementsThe elements from which one elements will be chosen randomly, must contain at least one element
Returns
The randomly selected element
Template Parameters
TThe data type of the element

◆ random() [3/14]

template<typename T >
T Ocean::RandomI::random ( const std::vector< T > &  elements)
static

Randomly returns one element from a given vector.

Parameters
elementsThe elements from which one elements will be chosen randomly, must contain at least one element
Returns
The randomly selected element
Template Parameters
TThe data type of the element

◆ random() [4/14]

static unsigned int Ocean::RandomI::random ( const unsigned int  lower,
const unsigned int  upper 
)
static

Returns one random integer value within a specific range.

Parameters
lowerThe lower border, with range [0, infinity)
upperThe upper border, with range [lower, infinity)
Returns
Random integer number, with range [lower, upper]

◆ random() [5/14]

static unsigned int Ocean::RandomI::random ( const unsigned int  maxValue)
static

Returns one random integer value with specified maximum value.

Parameters
maxValueMaximum value, with range [0, infinity)
Returns
Random integer number, with range [0, maxValue]

◆ random() [6/14]

static void Ocean::RandomI::random ( const unsigned int  maxValue,
unsigned int &  first,
unsigned int &  second 
)
static

Returns two different random integer values with specified maximum value.

Parameters
maxValueMaximum value, must be large enough to ensure two different random numbers, with range [1, infinity)
firstResulting first unique random number, with range [0, maxValue]
secondResulting second unique random number, with range [0, maxValue]

◆ random() [7/14]

static void Ocean::RandomI::random ( const unsigned int  maxValue,
unsigned int &  first,
unsigned int &  second,
unsigned int &  third 
)
static

Returns three different random integer values with specified maximum value.

Parameters
maxValueMaximum value, must be large enough to ensure three different random numbers, with range [2, infinity)
firstResulting first unique random number, with range [0, maxValue]
secondResulting second unique random number, with range [0, maxValue]
thirdResulting third unique random number, with range [0, maxValue]

◆ random() [8/14]

int Ocean::RandomI::random ( RandomGenerator randomGenerator,
const int  lower,
const int  upper 
)
inlinestatic

Returns one random integer value within a specific range using an explicit random generator.

Parameters
randomGeneratorThe random generator to be used
lowerThe lower border, with range (-infinity, infinity)
upperThe upper border, with range [lower, lower + 2147483647]
Returns
Random integer number, with range [lower, upper]

◆ random() [9/14]

template<typename T >
T Ocean::RandomI::random ( RandomGenerator randomGenerator,
const std::initializer_list< T > &  elements 
)
static

Randomly returns one element from a given initializer list.

Parameters
randomGeneratorThe random generator to be used
elementsThe elements from which one elements will be chosen randomly, must contain at least one element
Returns
The randomly selected element
Template Parameters
TThe data type of the element

◆ random() [10/14]

template<typename T >
T Ocean::RandomI::random ( RandomGenerator randomGenerator,
const std::vector< T > &  elements 
)
static

Randomly returns one element from a given vector.

Parameters
randomGeneratorThe random generator to be used
elementsThe elements from which one elements will be chosen randomly, must contain at least one element
Returns
The randomly selected element
Template Parameters
TThe data type of the element

◆ random() [11/14]

unsigned int Ocean::RandomI::random ( RandomGenerator randomGenerator,
const unsigned int  lower,
const unsigned int  upper 
)
inlinestatic

Returns one random integer value within a specific range using an explicit random generator.

Parameters
randomGeneratorThe random generator to be used
lowerThe lower border, with range [0, infinity)
upperThe upper border, with range [lower, infinity)
Returns
Random integer number, with range [lower, upper]

◆ random() [12/14]

unsigned int Ocean::RandomI::random ( RandomGenerator randomGenerator,
const unsigned int  maxValue 
)
inlinestatic

Returns one random integer value with specified maximum value using an explicit random generator.

Parameters
randomGeneratorThe random generator to be used
maxValueMaximum value, with range [0, infinity)
Returns
Random integer number, with range [0, maxValue]

◆ random() [13/14]

static void Ocean::RandomI::random ( RandomGenerator randomGenerator,
const unsigned int  maxValue,
unsigned int &  first,
unsigned int &  second 
)
static

Returns two different random integer values with specified maximum value using an explicit random generator.

Parameters
randomGeneratorThe random generator to be used
maxValueMaximum value, must be large enough to ensure three different random numbers, with range [1, infinity)
firstResulting first unique random number, with range [0, maxValue]
secondResulting second unique random number, with range [0, maxValue]

◆ random() [14/14]

static void Ocean::RandomI::random ( RandomGenerator randomGenerator,
const unsigned int  maxValue,
unsigned int &  first,
unsigned int &  second,
unsigned int &  third 
)
static

Returns three different random integer values with specified maximum value using an explicit random generator.

Parameters
randomGeneratorThe random generator to be used
maxValueMaximum value, must be large enough to ensure three different random numbers, with range [2, infinity)
firstResulting first unique random number, with range [0, maxValue]
secondResulting second unique random number, with range [0, maxValue]
thirdResulting third unique random number, with range [0, maxValue]

◆ random32() [1/2]

static uint32_t Ocean::RandomI::random32 ( )
static

Returns one random integer number with range [0x00000000, 0xFFFFFFFF].

Use this function only if the standard random() functions with range parameters are not large enough.

Returns
Random integer number, with range [0, infinity)

◆ random32() [2/2]

static uint32_t Ocean::RandomI::random32 ( RandomGenerator randomGenerator)
static

Returns one random integer number with range [0x00000000, 0xFFFFFFFF] using an explicit random generator.

Use this function only if the standard random() functions with range parameters are not large enough.

Parameters
randomGeneratorThe random generator to be used
Returns
Random integer number, with range [0, infinity)

◆ random64() [1/2]

static uint64_t Ocean::RandomI::random64 ( )
static

Returns one random integer number with range [0x00000000 00000000, 0xFFFFFFFF FFFFFFFF].

Use this function only if the standard random() functions with range parameters are not large enough.

Returns
Random integer number, with range [0, infinity)

◆ random64() [2/2]

static uint64_t Ocean::RandomI::random64 ( RandomGenerator randomGenerator)
static

Returns one random integer number with range [0x00000000 00000000, 0xFFFFFFFF FFFFFFFF] using an explicit random generator.

Use this function only if the standard random() functions with range parameters are not large enough.

Returns
Random integer number, with range [0, infinity)

◆ timeBasedSeed()

static unsigned int Ocean::RandomI::timeBasedSeed ( )
static

Returns a seed value based on the current time.

Returns
Time-based seed value

The documentation for this class was generated from the following file: