rand/xoshiro: add a std::seed_seq constructor

This commit is contained in:
Danny Robson 2020-08-18 07:19:55 +10:00
parent 3d5258b974
commit 5f4c95aa11
2 changed files with 20 additions and 0 deletions

View File

@ -36,6 +36,24 @@ xoshiro256plusplus::xoshiro256plusplus (u64 _seed)
}
//-----------------------------------------------------------------------------
xoshiro256plusplus::xoshiro256plusplus (std::seed_seq &seq)
{
std::generate (
std::begin (m_state),
std::end (m_state),
[&] (void) {
u64 parts[2];
seq.generate (
std::begin (parts),
std::end (parts)
);
return parts[0] << 4 | parts[1];
}
);
}
///////////////////////////////////////////////////////////////////////////////
u64
xoshiro256plusplus::operator() (void)

View File

@ -20,6 +20,7 @@
#include "../std.hpp"
#include <limits>
#include <random>
///////////////////////////////////////////////////////////////////////////////
@ -29,6 +30,7 @@ namespace cruft::rand {
using result_type = u64;
xoshiro256plusplus (u64 seed);
xoshiro256plusplus (std::seed_seq&);
static constexpr result_type min (void)
{