From 43682439fe86041f635c9c70e52bbf0b8085641c Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Sat, 18 Sep 2021 16:14:21 +0200 Subject: [PATCH] Added new random utilities with automatic min/max --- src/randomutils.h | 51 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/randomutils.h b/src/randomutils.h index ff910d1..6293df6 100644 --- a/src/randomutils.h +++ b/src/randomutils.h @@ -2,6 +2,7 @@ // system includes #include +#include namespace cpputils { @@ -47,10 +48,12 @@ T randomNumber(T min, T max, Trandom &&rng) // return dist(rng); //} + + template T randomNumber(T max, Trandom &rng) { - std::uniform_int_distribution dist{{}, max}; + std::uniform_int_distribution dist{std::numeric_limits::min(), max}; return dist(rng); } @@ -71,7 +74,7 @@ T randomNumber(T max, Trandom &rng) template T randomNumber(T max, Trandom &&rng) { - std::uniform_int_distribution dist{{}, max}; + std::uniform_int_distribution dist{std::numeric_limits::min(), max}; return dist(rng); } @@ -89,4 +92,48 @@ T randomNumber(T max, Trandom &&rng) // return dist(rng); //} + + +template +T randomNumber(Trandom &rng) +{ + std::uniform_int_distribution dist{std::numeric_limits::min(), std::numeric_limits::max()}; + return dist(rng); +} + +//template +//float randomNumber(Trandom &rng) +//{ +// std::uniform_real_distribution dist{{}, 1.f}; +// return dist(rng); +//} + +//template +//double randomNumber(Trandom &rng) +//{ +// std::uniform_real_distribution dist{{}, 1.}; +// return dist(rng); +//} + +template +T randomNumber(Trandom &&rng) +{ + std::uniform_int_distribution dist{std::numeric_limits::min(), std::numeric_limits::max()}; + return dist(rng); +} + +//template +//float randomNumber(Trandom &&rng) +//{ +// std::uniform_real_distribution dist{{}, 1.f}; +// return dist(rng); +//} + +//template +//double randomNumber(Trandom &&rng) +//{ +// std::uniform_real_distribution dist{{}, 1.}; +// return dist(rng); +//} + } // namespace cpputils