rippled
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
19 operator=(xor_shift_engine const&) = default;
20
21 explicit xor_shift_engine(result_type val = 1977u);
22
23 void
25
27 operator()();
28
29 static result_type constexpr min()
30 {
32 }
33
34 static result_type constexpr max()
35 {
37 }
38
39private:
41
42 static result_type
44};
45
46template <class _>
51
52template <class _>
53void
55{
56 if (seed == 0)
57 throw std::domain_error("invalid seed");
58 s_[0] = murmurhash3(seed);
59 s_[1] = murmurhash3(s_[0]);
60}
61
62template <class _>
63auto
65{
66 result_type s1 = s_[0];
67 result_type const s0 = s_[1];
68 s_[0] = s0;
69 s1 ^= s1 << 23;
70 return (s_[1] = (s1 ^ s0 ^ (s1 >> 17) ^ (s0 >> 26))) + s0;
71}
72
73template <class _>
74auto
76{
77 x ^= x >> 33;
78 x *= 0xff51afd7ed558ccdULL;
79 x ^= x >> 33;
80 x *= 0xc4ceb9fe1a85ec53ULL;
81 return x ^= x >> 33;
82}
83
84} // namespace detail
85
95
96} // namespace beast
static result_type constexpr min()
static result_type constexpr max()
xor_shift_engine & operator=(xor_shift_engine const &)=default
xor_shift_engine(xor_shift_engine const &)=default
static result_type murmurhash3(result_type x)
T max(T... args)
T min(T... args)