rippled
Loading...
Searching...
No Matches
xor_shift_engine.h
1#ifndef BEAST_RANDOM_XOR_SHIFT_ENGINE_H_INCLUDED
2#define BEAST_RANDOM_XOR_SHIFT_ENGINE_H_INCLUDED
3
4#include <cstdint>
5#include <limits>
6#include <stdexcept>
7
8namespace beast {
9
10namespace detail {
11
12template <class = void>
14{
15public:
17
20 operator=(xor_shift_engine const&) = default;
21
22 explicit xor_shift_engine(result_type val = 1977u);
23
24 void
26
28 operator()();
29
30 static result_type constexpr min()
31 {
33 }
34
35 static result_type constexpr max()
36 {
38 }
39
40private:
42
43 static result_type
45};
46
47template <class _>
52
53template <class _>
54void
56{
57 if (seed == 0)
58 throw std::domain_error("invalid seed");
59 s_[0] = murmurhash3(seed);
60 s_[1] = murmurhash3(s_[0]);
61}
62
63template <class _>
64auto
66{
67 result_type s1 = s_[0];
68 result_type const s0 = s_[1];
69 s_[0] = s0;
70 s1 ^= s1 << 23;
71 return (s_[1] = (s1 ^ s0 ^ (s1 >> 17) ^ (s0 >> 26))) + s0;
72}
73
74template <class _>
75auto
77{
78 x ^= x >> 33;
79 x *= 0xff51afd7ed558ccdULL;
80 x ^= x >> 33;
81 x *= 0xc4ceb9fe1a85ec53ULL;
82 return x ^= x >> 33;
83}
84
85} // namespace detail
86
96
97} // namespace beast
98
99#endif
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)