Use type_traits to decide what distribution to use in Random
This commit is contained in:
parent
a2837a107c
commit
823c0b37c6
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace simpleengine {
|
namespace simpleengine {
|
||||||
template<typename T, class RandomDevice = std::random_device, class Generator = std::mt19937>
|
template<typename T, class RandomDevice = std::random_device, class Generator = std::mt19937>
|
||||||
class Random {
|
class Random {
|
||||||
|
@ -20,7 +22,8 @@ namespace simpleengine {
|
||||||
this->gen = Generator(rd());
|
this->gen = Generator(rd());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Dist = std::uniform_int_distribution<>>
|
template<typename Dist = std::conditional_t<std::is_same_v<T, int> || std::is_same_v<T, uint32_t>,
|
||||||
|
std::uniform_int_distribution<T>, std::uniform_real_distribution<T>>>
|
||||||
T NextInRange(T min, T max) {
|
T NextInRange(T min, T max) {
|
||||||
Dist dist(min, max);
|
Dist dist(min, max);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue