From 5f4c95aa11d9dae70ffee4897dfe6d5de839f87c Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 18 Aug 2020 07:19:55 +1000 Subject: [PATCH] rand/xoshiro: add a std::seed_seq constructor --- rand/xoshiro.cpp | 18 ++++++++++++++++++ rand/xoshiro.hpp | 2 ++ 2 files changed, 20 insertions(+) diff --git a/rand/xoshiro.cpp b/rand/xoshiro.cpp index de35a65f..204324d7 100644 --- a/rand/xoshiro.cpp +++ b/rand/xoshiro.cpp @@ -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) diff --git a/rand/xoshiro.hpp b/rand/xoshiro.hpp index 1344c057..204e1548 100644 --- a/rand/xoshiro.hpp +++ b/rand/xoshiro.hpp @@ -20,6 +20,7 @@ #include "../std.hpp" #include +#include /////////////////////////////////////////////////////////////////////////////// @@ -29,6 +30,7 @@ namespace cruft::rand { using result_type = u64; xoshiro256plusplus (u64 seed); + xoshiro256plusplus (std::seed_seq&); static constexpr result_type min (void) {