1#define KBLIB_DEBUG_SEED_SEQ 1
13 SECTION(
"Mersenne Twister Engine") {
17 static_assert(kblib::state_size_v<std::mt19937> == 624,
".");
18 static_assert(kblib::state_size_v<std::mt19937_64> == 624,
".");
20 SECTION(
"Linear Congruential Engine") {
22 KBLIB_UNUSED auto gen = kblib::seeded<std::minstd_rand>();
24 static_assert(kblib::state_size_v<std::minstd_rand> == 1,
".");
25 static_assert(kblib::state_size_v<std::minstd_rand0> == 1,
".");
26 std::clog <<
"LCG(64): ";
27 KBLIB_UNUSED auto gen2 = kblib::seeded<kblib::lcgs::java_rand>();
29 static_assert(kblib::state_size_v<kblib::lcgs::java_rand> == 2,
".");
31 SECTION(
"Subtract with Carry Engine") {
32 std::clog <<
"SwCE 24: ";
33 KBLIB_UNUSED auto gen = kblib::seeded<std::ranlux24_base>();
34 std::clog <<
"SwCE 48: ";
35 KBLIB_UNUSED auto gen2 = kblib::seeded<std::ranlux24_base>();
37 static_assert(kblib::state_size_v<std::ranlux24_base> == 24,
".");
38 static_assert(kblib::state_size_v<std::ranlux48_base> == 24,
".");
40 SECTION(
"Discard Block Engine") {
43 = kblib::seeded<std::discard_block_engine<std::minstd_rand, 16, 8>>();
45 std::clog <<
"RANLUX 24: ";
50 std::discard_block_engine<std::minstd_rand, 16, 8>> == 1,
53 std::discard_block_engine<std::mt19937, 16, 8>> == 624,
55 static_assert(kblib::state_size_v<std::ranlux24> == 24,
".");
57 SECTION(
"Independent Bits Engine") {
60 =
kblib::seeded<std::independent_bits_engine<std::ranlux24, 32,
61 std::uint_fast32_t>>();
64 std::ranlux24, 32, std::uint_fast32_t>> == 24,
67 std::mt19937, 32, std::uint_fast32_t>> == 624,
70 std::minstd_rand, 32, std::uint_fast32_t>> == 1,
73 SECTION(
"Shuffle Order Engine") {
76 = kblib::seeded<std::shuffle_order_engine<std::ranlux24, 32>>();
79 std::shuffle_order_engine<std::ranlux24, 32>> == 24,
82 std::shuffle_order_engine<std::mt19937, 32>> == 624,
85 std::shuffle_order_engine<std::minstd_rand, 32>> == 1,
94 auto gen = kblib::seeded<E>();
95 static_assert(
E::min() == 0,
".");
102 decltype(gen) gen1, gen2;
103 REQUIRE(gen1 == gen2);
104 REQUIRE(gen != gen1);
105 REQUIRE(gen != gen2);
106 std::stringstream ss;
109 REQUIRE(gen == gen1);
110 REQUIRE(gen != gen2);
111 REQUIRE(gen1 != gen2);
113 std::uniform_int_distribution<int> dist;
constexpr struct kblib::nums::min_t min
constexpr struct kblib::nums::max_t max
auto seeded(Source &&s) -> Gen
constexpr std::size_t state_size_v
TEST_CASE("Random engine seeding")
Provides utilities to correctly and expressively use C++11's random number generation library,...
#define KBLIB_UNUSED
This internal macro is used to provide a fallback for [[maybe_unused]] in C++14.