diff --git a/rand/lcg.cpp b/rand/lcg.cpp index 31d9887c..37937407 100644 --- a/rand/lcg.cpp +++ b/rand/lcg.cpp @@ -56,6 +56,34 @@ lcg::operator() (void) } +/////////////////////////////////////////////////////////////////////////////// +template +typename lcg::result_type +lcg::min (void) +{ + return std::numeric_limits::min (); +} + + +//----------------------------------------------------------------------------- +template +typename lcg::result_type +lcg::max (void) +{ + return std::numeric_limits::max (); +} + + +/////////////////////////////////////////////////////////////////////////////// +template +void +lcg::discard (unsigned count) +{ + while (count--) + (*this)(); +} + + /////////////////////////////////////////////////////////////////////////////// template struct util::rand::lcg; template struct util::rand::lcg; diff --git a/rand/lcg.hpp b/rand/lcg.hpp index 8f2e74cc..e87ff243 100644 --- a/rand/lcg.hpp +++ b/rand/lcg.hpp @@ -30,11 +30,18 @@ namespace util { namespace rand { template struct lcg { public: + using result_type = T; + static_assert (std::is_unsigned::value, "LCG generates integer overflow which is undefined behaviour for signed types"); lcg (T seed); - T operator() (void); + result_type operator() (void); + + static result_type min (void); + static result_type max (void); + + void discard (unsigned); private: T m_x;