Ocean
|
This class provides base random functions and several random functions for integer data types. More...
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... | |
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.
|
inlinestatic |
Returns a random bool value.
|
inlinestatic |
Returns a random bool value.
randomGenerator | The random generator to be used |
|
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.
|
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.
value | Initialization value to be used, with range [0, infinity) |
|
staticconstexprprotected |
Returns the maximal random value of the default random number generator.
|
static |
Returns one random integer value within a specific range.
lower | The lower border, with range (-infinity, infinity) |
upper | The upper border, with range [lower, infinity) |
|
static |
Randomly returns one element from a given initializer list.
elements | The elements from which one elements will be chosen randomly, must contain at least one element |
T | The data type of the element |
|
static |
Randomly returns one element from a given vector.
elements | The elements from which one elements will be chosen randomly, must contain at least one element |
T | The data type of the element |
|
static |
Returns one random integer value within a specific range.
lower | The lower border, with range [0, infinity) |
upper | The upper border, with range [lower, infinity) |
|
static |
Returns one random integer value with specified maximum value.
maxValue | Maximum value, with range [0, infinity) |
|
static |
Returns two different random integer values with specified maximum value.
maxValue | Maximum value, must be large enough to ensure two different random numbers, with range [1, infinity) |
first | Resulting first unique random number, with range [0, maxValue] |
second | Resulting second unique random number, with range [0, maxValue] |
|
static |
Returns three different random integer values with specified maximum value.
maxValue | Maximum value, must be large enough to ensure three different random numbers, with range [2, infinity) |
first | Resulting first unique random number, with range [0, maxValue] |
second | Resulting second unique random number, with range [0, maxValue] |
third | Resulting third unique random number, with range [0, maxValue] |
|
inlinestatic |
Returns one random integer value within a specific range using an explicit random generator.
randomGenerator | The random generator to be used |
lower | The lower border, with range (-infinity, infinity) |
upper | The upper border, with range [lower, lower + 2147483647] |
|
static |
Randomly returns one element from a given initializer list.
randomGenerator | The random generator to be used |
elements | The elements from which one elements will be chosen randomly, must contain at least one element |
T | The data type of the element |
|
static |
Randomly returns one element from a given vector.
randomGenerator | The random generator to be used |
elements | The elements from which one elements will be chosen randomly, must contain at least one element |
T | The data type of the element |
|
inlinestatic |
Returns one random integer value within a specific range using an explicit random generator.
randomGenerator | The random generator to be used |
lower | The lower border, with range [0, infinity) |
upper | The upper border, with range [lower, infinity) |
|
inlinestatic |
Returns one random integer value with specified maximum value using an explicit random generator.
randomGenerator | The random generator to be used |
maxValue | Maximum value, with range [0, infinity) |
|
static |
Returns two different random integer values with specified maximum value using an explicit random generator.
randomGenerator | The random generator to be used |
maxValue | Maximum value, must be large enough to ensure three different random numbers, with range [1, infinity) |
first | Resulting first unique random number, with range [0, maxValue] |
second | Resulting second unique random number, with range [0, maxValue] |
|
static |
Returns three different random integer values with specified maximum value using an explicit random generator.
randomGenerator | The random generator to be used |
maxValue | Maximum value, must be large enough to ensure three different random numbers, with range [2, infinity) |
first | Resulting first unique random number, with range [0, maxValue] |
second | Resulting second unique random number, with range [0, maxValue] |
third | Resulting third unique random number, with range [0, maxValue] |
|
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.
|
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.
randomGenerator | The random generator to be used |
|
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.
|
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.
|
static |
Returns a seed value based on the current time.