diff options
author | Chaosus <chaosus89@gmail.com> | 2019-03-17 20:51:51 +0300 |
---|---|---|
committer | Chaosus <chaosus89@gmail.com> | 2019-03-27 19:37:25 +0300 |
commit | 6280be46a6fb62b8833a9d55bff590fb209b0fc6 (patch) | |
tree | d87540826d691bf6f533b14efa27dbc14c8ced44 /thirdparty/misc | |
parent | df7d3708c5b535c3696943322a14ec19a175e30c (diff) |
Properly setup seed in RNG
Diffstat (limited to 'thirdparty/misc')
-rw-r--r-- | thirdparty/misc/pcg.cpp | 10 | ||||
-rw-r--r-- | thirdparty/misc/pcg.h | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/thirdparty/misc/pcg.cpp b/thirdparty/misc/pcg.cpp index eac3b36d36..c421e16f89 100644 --- a/thirdparty/misc/pcg.cpp +++ b/thirdparty/misc/pcg.cpp @@ -13,3 +13,13 @@ uint32_t pcg32_random_r(pcg32_random_t* rng) uint32_t rot = oldstate >> 59u; return (xorshifted >> rot) | (xorshifted << ((-rot) & 31)); } + +// Source from http://www.pcg-random.org/downloads/pcg-c-basic-0.9.zip +void pcg32_srandom_r(pcg32_random_t* rng, uint64_t initstate, uint64_t initseq) +{ + rng->state = 0U; + rng->inc = (initseq << 1u) | 1u; + pcg32_random_r(rng); + rng->state += initstate; + pcg32_random_r(rng); +} diff --git a/thirdparty/misc/pcg.h b/thirdparty/misc/pcg.h index e2d66d51d5..6f42b3b094 100644 --- a/thirdparty/misc/pcg.h +++ b/thirdparty/misc/pcg.h @@ -10,5 +10,6 @@ typedef struct { uint64_t state; uint64_t inc; } pcg32_random_t; uint32_t pcg32_random_r(pcg32_random_t* rng); +void pcg32_srandom_r(pcg32_random_t* rng, uint64_t initstate, uint64_t initseq); #endif // RANDOM_H |