11#include <initializer_list>
20namespace ds::xoroshiro
25 using Debug = ConditionalDebug<
false,
"xoroshiro">;
36 template<
typename State,
48 static constexpr unsigned StateBits = 8 *
sizeof(State);
49 static constexpr unsigned ResultBits = 8 *
sizeof(Result);
51 static_assert(StateBits >= ResultBits,
52 "State must have at least as many bits as Result");
55 static_assert(0 <= A && A <= StateBits);
56 static_assert(0 <= B && B <= StateBits);
57 static_assert(0 <= C && C <= StateBits);
62 static inline State rotl(State x, State k)
64 return (x << k) | (x >> (StateBits - k));
67 void jump(State jump0, State jump1)
69 const State Jump[] = {jump0, jump1};
74 for (
int b = 0; b < 64; b++)
76 if (Jump[i] &
static_cast<uint64_t
>(1) << b)
89 XorOshiro(State x = 5489, State y = 0) : x(x), y(y)
92 Debug::Invariant((x != 0) || (y != 0),
93 "Invalid state, both x and y are zero");
98 void set_state(State nx, State ny = 0)
101 Debug::Invariant((nx != 0) || (ny != 0),
102 "Invalid state, both nx and ny are zero");
115 x = rotl(x, A) ^ y ^ (y << B);
118 Debug::Invariant((x != 0) || (y != 0),
119 "Invalid state, both x and y are zero after "
120 "next() with x: {}, y: {}",
123 return r >> (StateBits - ResultBits);
135 requires(Jump0 != 0) && (Jump1 != 0)
145 requires(LongJump0 != 0) && (LongJump1 != 0)
147 jump(LongJump0, LongJump1);
The xoroshiro+ (not ++) generator(s) of Blackman and Vigna's Scrambled Linear Pseudorandom Number Gen...
void long_jump()
Jump a really long way.
C++ APIs for assertions, invariants, and writing formatted debug messages to a UART.
detail::XorOshiro< uint32_t, uint16_t, 27, 7, 20 > P64R16
A "xoroshiro64+" with 16-bit outputs.
detail::XorOshiro< uint64_t, uint64_t, 24, 16, 37, 0xdf900294d8f554a5, 0x170865df4b3201fc, 0xd2a98b26625eee7b, 0xdddf9b1090aa7ac1 > P128R64
xoroshiro128+ with 64-bit output using the 2018 parameters.
detail::XorOshiro< uint8_t, uint8_t, 4, 7, 3 > P16R8
A "xoroshiro16+" with 8-bit outputs.
detail::XorOshiro< uint16_t, uint8_t, 13, 5, 10 > P32R8
A "xoroshiro32+" with 16-bit outputs.
detail::XorOshiro< uint64_t, uint32_t, 24, 16, 37 > P128R32
xoroshiro128+ with 32-bit output using the 2018 parameters.
detail::XorOshiro< uint32_t, uint32_t, 27, 7, 20 > P64R32
A "xoroshiro64+" with 32-bit outputs.
detail::XorOshiro< uint16_t, uint16_t, 13, 5, 10 > P32R16
A "xoroshiro32+" with 16-bit outputs.