diff --git a/include/boost/random/detail/xoshiro_base.hpp b/include/boost/random/detail/xoshiro_base.hpp index a70dbbde6..f9a794e7e 100644 --- a/include/boost/random/detail/xoshiro_base.hpp +++ b/include/boost/random/detail/xoshiro_base.hpp @@ -53,12 +53,12 @@ class xoshiro_base template inline void sseq_seed_64(Sseq& seq) { - for (auto& i : state_) - { - std::array seeds; - seq.generate(seeds.begin(), seeds.end()); + std::array seeds; + seq.generate(seeds.begin(), seeds.end()); - i = concatenate(seeds[0], seeds[1]); + for (std::size_t i = 0; i < state_.size(); ++i) + { + state_[i] = concatenate(seeds[2*i], seeds[2*i + 1]); } } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 46fa05af1..ff83427a9 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -87,6 +87,7 @@ run test_xoshiro128f.cpp /boost/test//boost_unit_test_framework ; run test_comp_xoshiro128f.cpp ; run github_issue_133.cpp ; +run github_issue_147.cpp ; run niederreiter_base2_validate.cpp /boost/test//boost_unit_test_framework ; run sobol_validate.cpp /boost/test//boost_unit_test_framework ; diff --git a/test/github_issue_147.cpp b/test/github_issue_147.cpp new file mode 100644 index 000000000..fa6f2c104 --- /dev/null +++ b/test/github_issue_147.cpp @@ -0,0 +1,57 @@ +/* +* Copyright Matt Borland 2025. + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include + +template +bool all_words_equal(const Arr& a) +{ + for (std::size_t i = 1; i < a.size(); ++i) + { + if (a[i] != a[0]) return false; + } + + return true; +} + +template +void test_engine_with_sseq(SSeq& sseq) +{ + Engine eng(sseq); + auto st = eng.state(); + BOOST_TEST(!all_words_equal(st)); +} + +int main() +{ + const std::vector seed_words = { + 0x12345678u, 0x9abcdef0u, 0xc0ffee12u, 0xdeadbeefu + }; + + // xoshiro128mm (4 x 32-bit state) + std::seed_seq stdseq(seed_words.begin(), seed_words.end()); + boost::random::seed_seq bseq(seed_words.begin(), seed_words.end()); + test_engine_with_sseq(stdseq); + test_engine_with_sseq(bseq); + + // xoshiro256mm (4 x 64-bit state) + std::seed_seq stdseq2(seed_words.begin(), seed_words.end()); + boost::random::seed_seq bseq2(seed_words.begin(), seed_words.end()); + test_engine_with_sseq(stdseq2); + test_engine_with_sseq(bseq2); + + return boost::report_errors(); +} diff --git a/test/test_xoshiro256d.cpp b/test/test_xoshiro256d.cpp index 9dab58c75..ee41a5bb1 100644 --- a/test/test_xoshiro256d.cpp +++ b/test/test_xoshiro256d.cpp @@ -19,7 +19,7 @@ // principal operation validated with CLHEP, values by experiment #define BOOST_RANDOM_VALIDATION_VALUE 0.91719108108351499 -#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 0.34930769688746899 +#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 0.68650209712672527 // Since we are using splitmix64 we need to allow 64 bit seeds // The test harness only allows for 32 bit seeds diff --git a/test/test_xoshiro256mm.cpp b/test/test_xoshiro256mm.cpp index 555f875e2..4eea5362f 100644 --- a/test/test_xoshiro256mm.cpp +++ b/test/test_xoshiro256mm.cpp @@ -19,6 +19,6 @@ // principal operation validated with CLHEP, values by experiment #define BOOST_RANDOM_VALIDATION_VALUE UINT64_C(2196391076106727935) -#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE UINT64_C(3823370830110671407) +#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE UINT64_C(8340052881247508375) #include "test_generator.ipp" diff --git a/test/test_xoshiro256pp.cpp b/test/test_xoshiro256pp.cpp index 0d2b1e470..b366ce92a 100644 --- a/test/test_xoshiro256pp.cpp +++ b/test/test_xoshiro256pp.cpp @@ -19,6 +19,6 @@ // principal operation validated with CLHEP, values by experiment #define BOOST_RANDOM_VALIDATION_VALUE UINT64_C(8911602566162972150) -#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE UINT64_C(11693002297289060464) +#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE UINT64_C(9091783836875527177) #include "test_generator.ipp" diff --git a/test/test_xoshiro512d.cpp b/test/test_xoshiro512d.cpp index 31988a316..363fa57d3 100644 --- a/test/test_xoshiro512d.cpp +++ b/test/test_xoshiro512d.cpp @@ -19,7 +19,7 @@ // principal operation validated with CLHEP, values by experiment #define BOOST_RANDOM_VALIDATION_VALUE 0.85594919700533156 -#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 0.25120475433393952 +#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 0.77731098639989704 // Since we are using splitmix64 we need to allow 64 bit seeds // The test harness only allows for 32 bit seeds diff --git a/test/test_xoshiro512mm.cpp b/test/test_xoshiro512mm.cpp index abe2c1b01..5ef405871 100644 --- a/test/test_xoshiro512mm.cpp +++ b/test/test_xoshiro512mm.cpp @@ -19,6 +19,6 @@ // principal operation validated with CLHEP, values by experiment #define BOOST_RANDOM_VALIDATION_VALUE UINT64_C(9446215307655316885) -#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE UINT64_C(13183137209047681026) +#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE UINT64_C(7700017102361224222) #include "test_generator.ipp" diff --git a/test/test_xoshiro512pp.cpp b/test/test_xoshiro512pp.cpp index da3003e8a..035b8a988 100644 --- a/test/test_xoshiro512pp.cpp +++ b/test/test_xoshiro512pp.cpp @@ -19,6 +19,6 @@ // principal operation validated with CLHEP, values by experiment #define BOOST_RANDOM_VALIDATION_VALUE UINT64_C(11685388408145467864) -#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE UINT64_C(15400500895396352743) +#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE UINT64_C(6773570493308843014) #include "test_generator.ipp"