From 5d585d405fc02372f27a3d9474e02b82e2de2a38 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 6 Nov 2020 12:27:29 +1000 Subject: [PATCH] random: add a generator parameter overload of uniform(ValueT) --- random.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/random.hpp b/random.hpp index f02819e7..eee83b27 100644 --- a/random.hpp +++ b/random.hpp @@ -115,6 +115,19 @@ namespace cruft::random { } + ///------------------------------------------------------------------------ + /// Return a value uniformly chosen between 0 and the given value. + /// + /// Interval bounds are treated as per the standard Generator + /// implementations; ie, inclusive for integers, exclusive upper for reals. + template + decltype(auto) + uniform (T hi, GeneratorT &&gen) + { + return uniform (T{0}, hi, std::forward (gen)); + } + + ///------------------------------------------------------------------------ /// Return a uniformly random value chosen on the interval [0,1) template <