summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-02-16 23:24:02 +0100
committerGitHub <noreply@github.com>2019-02-16 23:24:02 +0100
commitf6fcbcfe9eb09af63b545865d7341190519ac63e (patch)
treeed54a5ec63c4e5959fd11731ec11c077b7f36ed6
parent9402d2f9feaddae00012ee6c3da074097e15dd22 (diff)
parentf946b28f752998e8cf43a20f2458537e7c5fd120 (diff)
Merge pull request #25680 from Chaosus/random_fix
Fix random generation, to not always retrieve 0 after seed()
-rw-r--r--core/math/random_pcg.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h
index ef69bf7120..2a69d43904 100644
--- a/core/math/random_pcg.h
+++ b/core/math/random_pcg.h
@@ -45,7 +45,10 @@ public:
RandomPCG(uint64_t seed = DEFAULT_SEED, uint64_t inc = PCG_DEFAULT_INC_64);
- _FORCE_INLINE_ void seed(uint64_t seed) { pcg.state = seed; }
+ _FORCE_INLINE_ void seed(uint64_t seed) {
+ pcg.state = seed;
+ pcg32_random_r(&pcg); // Force changing internal state to avoid initial 0
+ }
_FORCE_INLINE_ uint64_t get_seed() { return pcg.state; }
void randomize();