24 static constexpr
const uint64_t A = 6364136223846793005ULL;
25 static inline constexpr uint32_t
26 ror32 (
const uint32_t bits,
const uint32_t offset)
29 return (bits >> offset) | (bits << (32 - offset));
31 static inline constexpr uint32_t
32 pcg_xsh_rr (
const uint64_t input)
36 return ror32 ((input ^ (input >> 18)) >> 27, input >> 59);
40 template<
class SeedSeq>
41 explicit Pcg32Rng (SeedSeq &seed_sequence) : increment_ (0), accu_ (0) {
seed (seed_sequence); }
43 explicit Pcg32Rng (uint64_t offset, uint64_t sequence) :
44 increment_ (0), accu_ (0)
46 seed (offset, sequence);
50 increment_ (0), accu_ (0)
60 seed (g_random_int(), g_random_int());
63 void seed (uint64_t offset, uint64_t sequence)
66 increment_ = (sequence << 1) | 1;
68 accu_ = A * accu_ + increment_;
71 template<
class SeedSeq>
void 72 seed (SeedSeq &seed_sequence)
75 seed_sequence.generate (&seeds[0], &seeds[2]);
76 seed (seeds[0], seeds[1]);
82 const uint64_t lcgout = accu_;
83 accu_ = A * accu_ + increment_;
84 return pcg_xsh_rr (lcgout);
uint32_t random()
Generate uniformly distributed 32 bit pseudo random number.
Definition: smpcg32rng.hh:80
void seed(uint64_t offset, uint64_t sequence)
Seed by seeking to position offset within stream sequence.
Definition: smpcg32rng.hh:63
Definition: smpcg32rng.hh:21
Pcg32Rng(SeedSeq &seed_sequence)
Initialize and seed from seed_sequence.
Definition: smpcg32rng.hh:41
void seed(SeedSeq &seed_sequence)
Seed the generator state from a seed_sequence.
Definition: smpcg32rng.hh:72
Definition: smalignedarray.cc:7
void auto_seed()
Seed the generator from a system specific nondeterministic random source.
Definition: smpcg32rng.hh:56
Pcg32Rng(uint64_t offset, uint64_t sequence)
Initialize and seed by seeking to position offset within stream sequence.
Definition: smpcg32rng.hh:43
Pcg32Rng()
Initialize and seed the generator from a system specific nondeterministic random source.
Definition: smpcg32rng.hh:49