35 #include <metaprogramming/LoopUnroll.hpp> 38 #define SITMO_RAND_MAX sitmo::prng_engine::max() 54 std::array<uint64_t,4> state;
55 std::array<uint32_t,8> output;
71 loopUnroll<0,5>([&work,
this](
const int j)
73 loopUnroll<0,2>([j,&work,
this](
const int i)
75 constexpr uint64_t mk[2][2]=
86 key[(2*i+1+j)%5]+((i==1)?j:0);
90 (x1<<rx)|(x1>>(64-rx));
94 loopUnroll<0,3>([j,&work](
const int l)
96 loopUnroll<0,2>([l,j,&work](
const int i)
98 constexpr uint64_t m[2][3][2]=
99 {{{52,57},{23,40},{5,37}},
100 {{46,12},{58,22},{32,32}}};
105 work[(2*i+((l%2==0)?3:1))%4];
112 (x1<<rx)|(x1>>(64-rx));
132 static constexpr uint32_t
max=
147 const uint32_t& k1=0,
148 const uint32_t& k2=0,
149 const uint32_t& k3=0)
160 0x1BD11BDAA9FC1A22^key[0]^key[1]^key[2]^key[3];
175 encryptCounter(ciphered.state);
206 encryptCounter(ciphered.state);
214 ciphered.output[iChunk++];
226 if (z < (uint64_t)(8 - iChunk)) {
227 iChunk +=
static_cast<
unsigned short>(z);
238 encryptCounter(ciphered.state);
245 for (
unsigned short i=0;
i<4; ++
i)
255 for (
unsigned short i=0;
i<4; ++
i)
265 for (
unsigned short i=0; i<4; ++i) {
266 if (state[i] != y.state[i])
return false;
267 if (key[i] != y.key[i])
return false;
268 if (ciphered.state[i] != y.ciphered.state[i])
return false;
276 return !(*
this == y);
280 void set_counter(uint64_t s0=0, uint64_t s1=0, uint64_t s2=0, uint64_t s3=0,
unsigned short o_counter=0)
287 encryptCounter(ciphered.state);
310 while(state[iDigit++]==0
and iDigit<4);
Sitmo & operator++(int)
Unitary increment.
Sitmo & operator+=(const uint64_t z)
Increments the counter by a given amount.
void setKey(const uint32_t &k0=0, const uint32_t &k1=0, const uint32_t &k2=0, const uint32_t &k3=0)
Sets the key.
bool operator==(const Sitmo &y)
Check that the two generators are the same.
void seed(const uint32_t &s=0)
Init using the passed seed.
Sitmo(const Sitmo &oth)
Copy constructor.
friend std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &is, Sitmo &s)
Input.
void set_counter(uint64_t s0=0, uint64_t s1=0, uint64_t s2=0, uint64_t s3=0, unsigned short o_counter=0)
Set the counter.
void discard(uint64_t z)
Advances e’s state ei to ei+z.
void encryptCounter(std::array< uint64_t, 4 > &outputState) const
Encrypts the counter, to set the state.
Sitmo(const uint32_t &s=0)
Construct from a seed.
uint32_t operator()()
Returns one of the 8 chunks.
bool operator!=(const Sitmo &y)
Check that the two generators are different.
unsigned short iChunk
Output chunk counter: determines wihch 32 of the 256 random bits in cipheredState is returned...