RandLib 2.0.0
Probability distributions, fitting, and heavy-tail tools for C++20
Loading...
Searching...
No Matches
legacy.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <cstdint>
6
11{
12
18{
19public:
20 using result_type = std::uint32_t;
21
22 explicit JKissEngine(std::uint64_t value = 0) noexcept { seed(value); }
23
24 static constexpr result_type min() noexcept { return 0; }
25 static constexpr result_type max() noexcept { return ~result_type{0}; }
26
27 void seed(std::uint64_t value) noexcept
28 {
29 SplitMix64 expand(value);
30 X = static_cast<std::uint32_t>(expand());
31 do {
32 Y = static_cast<std::uint32_t>(expand());
33 } while (Y == 0);
34 Z = static_cast<std::uint32_t>(expand());
35 C = 1 + static_cast<std::uint32_t>(expand() % 698769067ULL);
36 }
37
39 {
40 std::uint64_t t = 698769069ULL * Z + C;
41 X = 69069 * X + 12345;
42 Y ^= Y << 13;
43 Y ^= Y >> 17;
44 Y ^= Y << 5;
45 C = static_cast<std::uint32_t>(t >> 32);
46 Z = static_cast<std::uint32_t>(t);
47 return X + Y + Z;
48 }
49
50 friend bool operator==(const JKissEngine &, const JKissEngine &) = default;
51
52private:
53 std::uint32_t X = 0, Y = 1, Z = 0, C = 1;
54};
55
61{
62public:
63 using result_type = std::uint64_t;
64
65 explicit JLKiss64Engine(std::uint64_t value = 0) noexcept { seed(value); }
66
67 static constexpr result_type min() noexcept { return 0; }
68 static constexpr result_type max() noexcept { return ~result_type{0}; }
69
70 void seed(std::uint64_t value) noexcept
71 {
72 SplitMix64 expand(value);
73 X = expand();
74 do {
75 Y = expand();
76 } while (Y == 0);
77 Z1 = static_cast<std::uint32_t>(expand());
78 Z2 = static_cast<std::uint32_t>(expand());
79 C1 = 1 + static_cast<std::uint32_t>(expand() % 4294584391ULL);
80 C2 = 1 + static_cast<std::uint32_t>(expand() % 4246477507ULL);
81 }
82
84 {
85 X = 1490024343005336237ULL * X + 123456789;
86 Y ^= Y << 21;
87 Y ^= Y >> 17;
88 Y ^= Y << 30;
89 std::uint64_t t = 4294584393ULL * Z1 + C1;
90 C1 = static_cast<std::uint32_t>(t >> 32);
91 Z1 = static_cast<std::uint32_t>(t);
92 t = 4246477509ULL * Z2 + C2;
93 C2 = static_cast<std::uint32_t>(t >> 32);
94 Z2 = static_cast<std::uint32_t>(t);
95 return X + Y + Z1 + (static_cast<std::uint64_t>(Z2) << 32);
96 }
97
98 friend bool operator==(const JLKiss64Engine &, const JLKiss64Engine &) = default;
99
100private:
101 std::uint64_t X = 0, Y = 1;
102 std::uint32_t Z1 = 0, Z2 = 0, C1 = 1, C2 = 1;
103};
104
105} // namespace randlib::legacy
The SplitMix64 class Sebastiano Vigna's SplitMix64 generator.
Definition splitmix64.hpp:14
The JKissEngine class David Jones' JKISS generator with 32-bit output.
Definition legacy.hpp:18
std::uint32_t result_type
Definition legacy.hpp:20
static constexpr result_type min() noexcept
Definition legacy.hpp:24
friend bool operator==(const JKissEngine &, const JKissEngine &)=default
JKissEngine(std::uint64_t value=0) noexcept
Definition legacy.hpp:22
result_type operator()() noexcept
Definition legacy.hpp:38
static constexpr result_type max() noexcept
Definition legacy.hpp:25
void seed(std::uint64_t value) noexcept
Definition legacy.hpp:27
The JLKiss64Engine class David Jones' JLKISS64 generator with 64-bit output.
Definition legacy.hpp:61
JLKiss64Engine(std::uint64_t value=0) noexcept
Definition legacy.hpp:65
result_type operator()() noexcept
Definition legacy.hpp:83
static constexpr result_type min() noexcept
Definition legacy.hpp:67
friend bool operator==(const JLKiss64Engine &, const JLKiss64Engine &)=default
void seed(std::uint64_t value) noexcept
Definition legacy.hpp:70
static constexpr result_type max() noexcept
Definition legacy.hpp:68
std::uint64_t result_type
Definition legacy.hpp:63
Engines of RandLib 1.x, kept for comparison with older results.
Definition legacy.hpp:11