Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions include/boost/random/detail/xoshiro_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class xoshiro_base
template <typename Sseq>
inline void sseq_seed_64(Sseq& seq)
{
for (auto& i : state_)
{
std::array<std::uint32_t, 2> seeds;
seq.generate(seeds.begin(), seeds.end());
std::array<std::uint32_t, N * 2> 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]);
}
}

Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down
57 changes: 57 additions & 0 deletions test/github_issue_147.cpp
Original file line number Diff line number Diff line change
@@ -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 <boost/random.hpp>
#include <boost/core/lightweight_test.hpp>
#include <array>
#include <vector>
#include <random>
#include <cstdint>

template <class Arr>
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 <class Engine, class SSeq>
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<std::uint32_t> 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<boost::random::xoshiro128mm>(stdseq);
test_engine_with_sseq<boost::random::xoshiro128mm>(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<boost::random::xoshiro256mm>(stdseq2);
test_engine_with_sseq<boost::random::xoshiro256mm>(bseq2);

return boost::report_errors();
}
2 changes: 1 addition & 1 deletion test/test_xoshiro256d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_xoshiro256mm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion test/test_xoshiro256pp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion test/test_xoshiro512d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_xoshiro512mm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion test/test_xoshiro512pp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading