xrpld
Loading...
Searching...
No Matches
xor_shift_engine.h
1#pragma once
2
3#include <cstdint>
4#include <limits>
5#include <stdexcept>
6
7namespace beast {
8
9namespace detail {
10
11template <class = void>
13{
14public:
16
17 XorShiftEngine(XorShiftEngine const&) = default;
19 operator=(XorShiftEngine const&) = default;
20
21 explicit XorShiftEngine(result_type val = 1977u);
22
23 void
25
27 operator()();
28
29 static constexpr result_type
34
35 static constexpr result_type
40
41private:
43
44 static result_type
46};
47
48template <class Unused>
53
54template <class Unused>
55void
57{
58 if (seed == 0)
59 throw std::domain_error("invalid seed");
60 s_[0] = murmurhash3(seed);
61 s_[1] = murmurhash3(s_[0]);
62}
63
64template <class Unused>
65auto
67{
68 result_type s1 = s_[0];
69 result_type const s0 = s_[1];
70 s_[0] = s0;
71 s1 ^= s1 << 23;
72 return (s_[1] = (s1 ^ s0 ^ (s1 >> 17) ^ (s0 >> 26))) + s0;
73}
74
75template <class Unused>
76auto
78{
79 x ^= x >> 33;
80 x *= 0xff51afd7ed558ccdULL;
81 x ^= x >> 33;
82 x *= 0xc4ceb9fe1a85ec53ULL;
83 return x ^= x >> 33;
84}
85
86} // namespace detail
87
97
98} // namespace beast
static constexpr result_type min()
static constexpr result_type max()
void seed(result_type seed)
XorShiftEngine(XorShiftEngine const &)=default
static result_type murmurhash3(result_type x)
XorShiftEngine & operator=(XorShiftEngine const &)=default
T max(T... args)
T min(T... args)
detail::XorShiftEngine<> xor_shift_engine
XOR-shift Generator.