random: add uniform integer generator for whole range

This commit is contained in:
Danny Robson 2017-09-21 15:58:26 +10:00
parent b04f0b0c9e
commit d67a990de3

View File

@ -18,6 +18,7 @@
#define CRUFT_UTIL_RANDOM_HPP
#include <random>
#include <limits>
namespace util::random {
@ -52,6 +53,18 @@ namespace util::random {
}
///////////////////////////////////////////////////////////////////////////
template <typename T>
std::enable_if_t<std::is_integral_v<T>,T>
uniform (void)
{
return uniform (
std::numeric_limits<T>::min (),
std::numeric_limits<T>::max ()
);
}
///////////////////////////////////////////////////////////////////////////
/// choose a value at random from an array
template <typename T, size_t N>