12 static constexpr uint64_t S0 = 0x9b60939458e17d7e;
13 static constexpr uint64_t S1 = 0xd737232eeccdf7ed;
15 static constexpr
inline uint64_t rotl(
const uint64_t x,
int k) {
16 return (x << k) | (x >> (64 - k));
23 : _s{s0, s1}, _count(0) {}
26 using result_type = uint64_t;
31 : _s{rhs._s[0], rhs._s[1]}, _count(rhs._count) {}
37 template <typename Sseq, typename = typename std::enable_if<!std::is_same<Sseq, xoroshiro128plus>::value>::type>
49 static constexpr
auto min() noexcept -> result_type {
return std::numeric_limits<result_type>::min(); }
50 static constexpr
auto max() noexcept -> result_type {
return std::numeric_limits<result_type>::max(); }
52 constexpr
auto operator () () noexcept -> result_type {
53 const uint64_t result = _s[0] + _s[1];
55 const uint64_t s0 = rotl(_s[0], 24) ^ _s[0] ^ _s[1] ^ ((_s[0] ^ _s[1]) << 16);
56 const uint64_t s1 = rotl(_s[0] ^ _s[1], 37);
64 constexpr
void prev() noexcept {
65 const uint64_t x = rotl(_s[1], 27);
66 _s[0] = rotl(_s[0] ^ x ^ (x << 16), 40);
71 constexpr
void seed() {
76 constexpr
void seed(result_type r) {
77 uint64_t z = r += 0x9E3779B97F4A7C15;
78 z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9;
79 z = (z ^ (z >> 27)) * 0x94D049BB133111EB;
80 _s[0] = z ^ (z >> 31);
82 z = r += 0x9E3779B97F4A7C15;
83 z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9;
84 z = (z ^ (z >> 27)) * 0x94D049BB133111EB;
85 _s[1] = z ^ (z >> 31);
88 template <
typename Sseq>
89 typename std::enable_if<std::is_class<Sseq>::value>::type seed(Sseq& q) {
90 q.generate(_s, _s + 2);
93 constexpr
void discard(uint64_t n) noexcept {
94 for (
unsigned long long i = 0; i < n; ++i) {
99 void jump() noexcept {
100 static const uint64_t JUMP[2] = {
108 for (
int b = 0; b < 64; ++b) {
109 if (JUMP[0] & UINT64_C(1) << b) {
116 for (
int b = 0; b < 64; ++b) {
117 if (JUMP[1] & UINT64_C(1) << b) {
129 void long_jump() noexcept {
130 static const uint64_t JUMP[2] = {
138 for (
int b = 0; b < 64; ++b) {
139 if (JUMP[0] & UINT64_C(1) << b) {
146 for (
int b = 0; b < 64; ++b) {
147 if (JUMP[1] & UINT64_C(1) << b) {
159 constexpr uint64_t count() noexcept {
return _count; }
161 virtual void pup(PUP::er& p) {
168 return _s[0] == rhs._s[0] && _s[1] == rhs._s[1];
172 return !(*
this == rhs);
175 friend auto operator << (std::ostream& os,
const xoroshiro128plus& rhs) -> std::ostream& {
176 os << rhs._s[0] <<
' ' << rhs._s[1];
180 friend auto operator >> (std::istream& is,
xoroshiro128plus& rhs) -> std::istream& {
Definition: xoroshiro.h:10