Use type_traits to decide what distribution to use in Random

This commit is contained in:
SeanOMik 2021-03-22 18:55:21 -05:00
parent a2837a107c
commit 823c0b37c6
No known key found for this signature in database
GPG Key ID: CA09E5BE1F32728A
1 changed files with 4 additions and 1 deletions

View File

@ -9,6 +9,8 @@
#include <limits>
#include <random>
#include <type_traits>
namespace simpleengine {
template<typename T, class RandomDevice = std::random_device, class Generator = std::mt19937>
class Random {
@ -20,7 +22,8 @@ namespace simpleengine {
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) {
Dist dist(min, max);