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) & 31));
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);
Definition: smpcg32rng.hh:24
Pcg32Rng()
Initialize and seed the generator from a system specific nondeterministic random source.
Definition: smpcg32rng.hh:52
void auto_seed()
Seed the generator from a system specific nondeterministic random source.
Definition: smpcg32rng.hh:59
void seed(uint64_t offset, uint64_t sequence)
Seed by seeking to position offset within stream sequence.
Definition: smpcg32rng.hh:66
void seed(SeedSeq &seed_sequence)
Seed the generator state from a seed_sequence.
Definition: smpcg32rng.hh:75
uint32_t random()
Generate uniformly distributed 32 bit pseudo random number.
Definition: smpcg32rng.hh:83
Pcg32Rng(SeedSeq &seed_sequence)
Initialize and seed from seed_sequence.
Definition: smpcg32rng.hh:44
Pcg32Rng(uint64_t offset, uint64_t sequence)
Initialize and seed by seeking to position offset within stream sequence.
Definition: smpcg32rng.hh:46