|
| 1 | +/* |
| 2 | +* Copyright Matt Borland 2025. |
| 3 | + * Distributed under the Boost Software License, Version 1.0. (See |
| 4 | + * accompanying file LICENSE_1_0.txt or copy at |
| 5 | + * http://www.boost.org/LICENSE_1_0.txt) |
| 6 | + * |
| 7 | + * See http://www.boost.org for most recent version including documentation. |
| 8 | + * |
| 9 | + * $Id$ |
| 10 | + */ |
| 11 | + |
| 12 | +#include <boost/random.hpp> |
| 13 | +#include <boost/core/lightweight_test.hpp> |
| 14 | +#include <array> |
| 15 | +#include <vector> |
| 16 | +#include <random> |
| 17 | +#include <cstdint> |
| 18 | + |
| 19 | +template <class Arr> |
| 20 | +bool all_words_equal(const Arr& a) |
| 21 | +{ |
| 22 | + for (std::size_t i = 1; i < a.size(); ++i) |
| 23 | + { |
| 24 | + if (a[i] != a[0]) return false; |
| 25 | + } |
| 26 | + |
| 27 | + return true; |
| 28 | +} |
| 29 | + |
| 30 | +template <class Engine, class SSeq> |
| 31 | +void test_engine_with_sseq(SSeq& sseq) |
| 32 | +{ |
| 33 | + Engine eng(sseq); |
| 34 | + auto st = eng.state(); |
| 35 | + BOOST_TEST(!all_words_equal(st)); |
| 36 | +} |
| 37 | + |
| 38 | +int main() |
| 39 | +{ |
| 40 | + const std::vector<std::uint32_t> seed_words = { |
| 41 | + 0x12345678u, 0x9abcdef0u, 0xc0ffee12u, 0xdeadbeefu |
| 42 | + }; |
| 43 | + |
| 44 | + // xoshiro128mm (4 x 32-bit state) |
| 45 | + std::seed_seq stdseq(seed_words.begin(), seed_words.end()); |
| 46 | + boost::random::seed_seq bseq(seed_words.begin(), seed_words.end()); |
| 47 | + test_engine_with_sseq<boost::random::xoshiro128mm>(stdseq); |
| 48 | + test_engine_with_sseq<boost::random::xoshiro128mm>(bseq); |
| 49 | + |
| 50 | + // xoshiro256mm (4 x 64-bit state) |
| 51 | + std::seed_seq stdseq2(seed_words.begin(), seed_words.end()); |
| 52 | + boost::random::seed_seq bseq2(seed_words.begin(), seed_words.end()); |
| 53 | + test_engine_with_sseq<boost::random::xoshiro256mm>(stdseq2); |
| 54 | + test_engine_with_sseq<boost::random::xoshiro256mm>(bseq2); |
| 55 | + |
| 56 | + return boost::report_errors(); |
| 57 | +} |
0 commit comments