4 #ifndef SPECTMORPH_PCG32_RNG_HH
5 #define SPECTMORPH_PCG32_RNG_HH
27 static constexpr
const uint64_t A = 6364136223846793005ULL;
28 static inline constexpr uint32_t
29 ror32 (
const uint32_t bits,
const uint32_t offset)
32 return (bits >> offset) | (bits << (32 - offset));
34 static inline constexpr uint32_t
35 pcg_xsh_rr (
const uint64_t input)
39 return ror32 ((input ^ (input >> 18)) >> 27, input >> 59);
43 template<
class SeedSeq>
44 explicit Pcg32Rng (SeedSeq &seed_sequence) : increment_ (0), accu_ (0) {
seed (seed_sequence); }
46 explicit Pcg32Rng (uint64_t offset, uint64_t sequence) :
47 increment_ (0), accu_ (0)
49 seed (offset, sequence);
53 increment_ (0), accu_ (0)
63 seed (g_random_int(), g_random_int());
66 void seed (uint64_t offset, uint64_t sequence)
69 increment_ = (sequence << 1) | 1;
71 accu_ = A * accu_ + increment_;
74 template<
class SeedSeq>
void
75 seed (SeedSeq &seed_sequence)
78 seed_sequence.generate (&seeds[0], &seeds[2]);
79 seed (seeds[0], seeds[1]);
85 const uint64_t lcgout = accu_;
86 accu_ = A * accu_ + increment_;
87 return pcg_xsh_rr (lcgout);