diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-04-01 17:17:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-01 17:17:30 +0200 |
commit | 29a1202d39b0efb617a8ff4ee9764612f3e0124f (patch) | |
tree | ae139220628ef18ce35a14d47a5aaefab3cceae1 /core | |
parent | 18ee888541de80307da68808f3996ae2b0a807ab (diff) | |
parent | 6280be46a6fb62b8833a9d55bff590fb209b0fc6 (diff) |
Merge pull request #27171 from Chaosus/randfix
Properly setup seed in RNG
Diffstat (limited to 'core')
-rw-r--r-- | core/math/random_pcg.cpp | 3 | ||||
-rw-r--r-- | core/math/random_pcg.h | 6 |
2 files changed, 4 insertions, 5 deletions
diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp index 45467b32b2..8351bd138e 100644 --- a/core/math/random_pcg.cpp +++ b/core/math/random_pcg.cpp @@ -34,8 +34,7 @@ RandomPCG::RandomPCG(uint64_t p_seed, uint64_t p_inc) : pcg(), - current_seed(DEFAULT_SEED) { - pcg.inc = p_inc; + current_inc(p_inc) { seed(p_seed); } diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h index 230eb9a11b..cd721ef4d1 100644 --- a/core/math/random_pcg.h +++ b/core/math/random_pcg.h @@ -38,18 +38,18 @@ class RandomPCG { pcg32_random_t pcg; uint64_t current_seed; // seed with this to get the same state + uint64_t current_inc; public: static const uint64_t DEFAULT_SEED = 12047754176567800795U; static const uint64_t DEFAULT_INC = PCG_DEFAULT_INC_64; static const uint64_t RANDOM_MAX = 0xFFFFFFFF; - RandomPCG(uint64_t p_seed = DEFAULT_SEED, uint64_t p_inc = PCG_DEFAULT_INC_64); + RandomPCG(uint64_t p_seed = DEFAULT_SEED, uint64_t p_inc = DEFAULT_INC); _FORCE_INLINE_ void seed(uint64_t p_seed) { current_seed = p_seed; - pcg.state = p_seed; - pcg32_random_r(&pcg); // Force changing internal state to avoid initial 0 + pcg32_srandom_r(&pcg, current_seed, current_inc); } _FORCE_INLINE_ uint64_t get_seed() { return current_seed; } |