From 2bf3e3c4318e4d883329a67a654914a900211c20 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 1 Jul 2016 16:26:25 +1000 Subject: [PATCH] rand/xorshift: add min/max/discard operations --- rand/xorshift.cpp | 27 +++++++++++++++++++++++++++ rand/xorshift.hpp | 9 ++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/rand/xorshift.cpp b/rand/xorshift.cpp index c7170932..df1f1c42 100644 --- a/rand/xorshift.cpp +++ b/rand/xorshift.cpp @@ -74,6 +74,33 @@ xorshift::operator() (void) }; +/////////////////////////////////////////////////////////////////////////////// +template +typename xorshift::result_type +xorshift::min (void) +{ + return 1u; +} + +//----------------------------------------------------------------------------- +template +typename xorshift::result_type +xorshift::max (void) +{ + return std::numeric_limits::max (); +} + + +/////////////////////////////////////////////////////////////////////////////// +template +void +xorshift::discard (unsigned count) +{ + while (count--) + (*this)(); +} + + /////////////////////////////////////////////////////////////////////////////// template struct util::rand::xorshift; template struct util::rand::xorshift; diff --git a/rand/xorshift.hpp b/rand/xorshift.hpp index 7837c922..ccef2e81 100644 --- a/rand/xorshift.hpp +++ b/rand/xorshift.hpp @@ -26,9 +26,16 @@ namespace util { namespace rand { template struct xorshift { public: + using result_type = T; + xorshift (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_state;