A templated class for generating random numbers of a specified arithmetic type. More...
#include <random_gen_value.h>
Static Public Member Functions | |
static RandType | random (const RandType min, const RandType max) |
Compile-time assertion to ensure RandType is an arithmetic type. If RandType is not arithmetic (e.g., a custom class), a compilation error will occur. | |
template<int MAX_TRY = 100> | |
static RandType | random_except (const RandType min, const RandType max, const RandType except) |
Generates a random number within a specified range, excluding a particular value. | |
A templated class for generating random numbers of a specified arithmetic type.
This class provides static methods to generate random numbers within a given range, supporting both integral and floating-point types. It also includes a method to generate a random number while excluding a specific value.
RandType | The type of random number to generate. Must be an arithmetic type. |
|
inlinestatic |
Compile-time assertion to ensure RandType is an arithmetic type. If RandType is not arithmetic (e.g., a custom class), a compilation error will occur.
Generates a random number within a specified range [min, max].
std::random_device
for non-deterministic seeding and std::mt19937
as the random number engine. It employs std::uniform_int_distribution
for integral types and std::uniform_real_distribution
for floating-point types to ensure uniform distribution.min | The minimum possible value in the random range (inclusive). |
max | The maximum possible value in the random range (inclusive). |
RandType
within the specified range. std::logic_error | if RandType is not an integral or floating-point type (though static_assert should catch this at compile time). |
< Non-deterministic random number generator.
< Mersenne Twister engine seeded by rd.
< Distribution for integral types.
< Non-deterministic random number generator.
< Mersenne Twister engine seeded by rd.
< Distribution for floating-point types.
|
inlinestatic |
Generates a random number within a specified range, excluding a particular value.
random(min, max)
up to MAX_TRY
times until a value different from except
is generated.MAX_TRY | The maximum number of attempts to generate a value different from except . Defaults to 100. |
min | The minimum possible value in the random range (inclusive). |
max | The maximum possible value in the random range (inclusive). |
except | The value to be excluded from the generated random numbers. |
RandType
within the specified range, not equal to except
. std::logic_error | if the range [min, max] only contains the except value, making generation impossible. |
std::runtime_error | if a value different from except cannot be generated within MAX_TRY attempts. |