rand/xorshift: add min/max/discard operations

This commit is contained in:
Danny Robson 2016-07-01 16:26:25 +10:00
parent 138cac23fe
commit 2bf3e3c431
2 changed files with 35 additions and 1 deletions

View File

@ -74,6 +74,33 @@ xorshift<T>::operator() (void)
};
///////////////////////////////////////////////////////////////////////////////
template <typename T>
typename xorshift<T>::result_type
xorshift<T>::min (void)
{
return 1u;
}
//-----------------------------------------------------------------------------
template <typename T>
typename xorshift<T>::result_type
xorshift<T>::max (void)
{
return std::numeric_limits<T>::max ();
}
///////////////////////////////////////////////////////////////////////////////
template <typename T>
void
xorshift<T>::discard (unsigned count)
{
while (count--)
(*this)();
}
///////////////////////////////////////////////////////////////////////////////
template struct util::rand::xorshift<uint32_t>;
template struct util::rand::xorshift<uint64_t>;

View File

@ -26,9 +26,16 @@ namespace util { namespace rand {
template <typename T>
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;