better number gen

master
CompiledCode 3 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. * llo::utils::generate_random, generate a random numerical value.
```cpp ```cpp
template <class T> template<typename number_t, typename = typename std::enable_if_t<std::is_arithmetic_v<number_t>, number_t>>
auto generate_random() -> T number_t generate_random_number(const number_t minimum, const number_t maximum)
{ {
std::random_device rd; using uniform_distribution_t = std::conditional_t<std::is_integral_v<number_t>, std::uniform_int_distribution<number_t>, std::uniform_real_distribution<>>;
std::mt19937 mt(rd());
std::uniform_real_distribution<double> dist(1.0, 10.0); std::random_device random_device;
return dist(mt);
auto mt = std::mt19937{ random_device() };
auto uniform_distribution = uniform_distribution_t{ minimum, maximum };
return uniform_distribution(mt);
} }
``` ```

Loading…
Cancel
Save