generate_random_number = c++20 now 💪

master
CompiledCode 3 years ago
parent 9e4b176950
commit db933b9f20

@ -5,17 +5,20 @@ This repo contains a list of utils that will probably need to be implimented for
* llo::utils::generate_random_number, generate a random numerical value.
```cpp
template<typename number_t, typename = std::enable_if_t<std::is_arithmetic_v<number_t>, number_t>>
template <typename number_t>
concept is_arithmetic_t = std::is_arithmetic_v<number_t>;
template <is_arithmetic_t number_t>
number_t generate_random_number(const number_t minimum, const number_t maximum)
{
using uniform_distribution_t = std::conditional_t<std::is_integral_v<number_t>, std::uniform_int_distribution<number_t>, std::uniform_real_distribution<number_t>>;
std::random_device random_device;
auto mt = std::mt19937{ random_device() };
auto uniform_distribution = uniform_distribution_t{ minimum, maximum };
return uniform_distribution(mt);
}
```

Loading…
Cancel
Save