better number gen

master
CompiledCode 4 years ago
parent 9d5d4f0338
commit 05ceb78f91

@ -5,13 +5,18 @@ This repo contains a list of utils that will probably need to be implimented for
* llo::utils::generate_random, generate a random numerical value.
```cpp
template <class T>
auto generate_random() -> T
template<typename number_t, typename = typename std::enable_if_t<std::is_arithmetic_v<number_t>, number_t>>
number_t generate_random_number(const number_t minimum, const number_t maximum)
{
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<double> dist(1.0, 10.0);
return dist(mt);
using uniform_distribution_t = std::conditional_t<std::is_integral_v<number_t>, std::uniform_int_distribution<number_t>, std::uniform_real_distribution<>>;
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