Utility class for generating random values with optional seeding and support for multiple numeric types.
More...
#include <math.hpp>
|
template<typename T> |
static const T | value (const T min, const T max, const size_t seed=(std::numeric_limits< size_t >::max)()) |
| Generate a uniformly distributed random value in [min, max].
|
template<typename T> |
static const T | value (const T min, const T max, std::mt19937 &mt19937) |
| Generate a uniformly distributed random value in [min, max] using a provided mt19937 engine.
|
template<typename T> |
static const T | valueFromRandomRange (const std::vector< std::pair< T, T > > &ranges, const size_t seed=(std::numeric_limits< size_t >::max)()) |
| Generate a uniformly distributed random value from multiple specified ranges.
|
template<typename T> |
static const T | valueFromRandomRange (const std::vector< std::pair< T, T > > &ranges, std::mt19937 &mt19937) |
| Generate a uniformly distributed random value from multiple specified ranges using external mt19937 engine.
|
Utility class for generating random values with optional seeding and support for multiple numeric types.
Provides static methods to generate uniformly distributed random numbers for integral and floating-point types. Supports generating random values within a specified range, optionally with a user-provided seed or external random engine. Also supports choosing random values from multiple ranges.
◆ value() [1/2]
const T dz::Random::value |
( |
const T | min, |
|
|
const T | max, |
|
|
const size_t | seed = (std::numeric_limits<size_t>::max)() ) |
|
inlinestatic |
Generate a uniformly distributed random value in [min, max].
If a seed is provided (not the default max size_t), a new temporary mt19937 engine is created and seeded with the given seed. Otherwise, the internal static mt19937 engine is reseeded with the current time and used.
Supports floating point and integral types. Throws std::runtime_error if called with unsupported type.
- Template Parameters
-
T | Numeric type for the random value (must be integral or floating point). |
- Parameters
-
min | Minimum value of the random range (inclusive). |
max | Maximum value of the random range (inclusive for integral, [min,max) for floating point). |
seed | Optional seed to create a temporary mt19937 engine. Default is max size_t (no seed). |
- Returns
- Randomly generated value of type T.
- Exceptions
-
std::runtime_error | if T is not supported. |
◆ value() [2/2]
const T dz::Random::value |
( |
const T | min, |
|
|
const T | max, |
|
|
std::mt19937 & | mt19937 ) |
|
inlinestatic |
Generate a uniformly distributed random value in [min, max] using a provided mt19937 engine.
Supports floating point and integral types. Throws std::runtime_error if called with unsupported type.
- Template Parameters
-
T | Numeric type for the random value. |
- Parameters
-
min | Minimum value of the random range (inclusive). |
max | Maximum value of the random range (inclusive for integral, [min,max) for floating point). |
mt19937 | Reference to an external mt19937 random engine to use. |
- Returns
- Randomly generated value of type T.
- Exceptions
-
std::runtime_error | if T is not supported. |
◆ valueFromRandomRange() [1/2]
const T dz::Random::valueFromRandomRange |
( |
const std::vector< std::pair< T, T > > & | ranges, |
|
|
const size_t | seed = (std::numeric_limits<size_t>::max)() ) |
|
inlinestatic |
Generate a uniformly distributed random value from multiple specified ranges.
Selects one range at random, then generates a random value within that range. Optionally accepts a seed to create a temporary mt19937 engine, otherwise uses internal engine reseeded with current time.
- Template Parameters
-
T | Numeric type for the random value. |
- Parameters
-
ranges | Vector of pairs representing inclusive ranges [first, second]. |
seed | Optional seed to create a temporary mt19937 engine. Default is max size_t (no seed). |
- Returns
- Randomly generated value of type T from one of the specified ranges.
◆ valueFromRandomRange() [2/2]
const T dz::Random::valueFromRandomRange |
( |
const std::vector< std::pair< T, T > > & | ranges, |
|
|
std::mt19937 & | mt19937 ) |
|
inlinestatic |
Generate a uniformly distributed random value from multiple specified ranges using external mt19937 engine.
Selects one range at random, then generates a random value within that range.
- Template Parameters
-
T | Numeric type for the random value. |
- Parameters
-
ranges | Vector of pairs representing inclusive ranges [first, second]. |
mt19937 | Reference to an external mt19937 random engine to use. |
- Returns
- Randomly generated value of type T from one of the specified ranges.
The documentation for this struct was generated from the following file: