diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-04-18 00:06:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-18 00:06:41 +0200 |
commit | 7088d9e30f7afd8ca9cf262fc340266d4218808c (patch) | |
tree | 66d8d02f152060725ae6a2e153139adce9fa846b | |
parent | 24b2186ff94f04ccf64050a0382f2b8b5aaf4b2f (diff) | |
parent | ceb699f5ec50a69c8c9c37f4ed146cc0dd492f87 (diff) |
Merge pull request #8441 from tagcup/seed_fix
Fix PRNG randomization.
-rw-r--r-- | core/math/math_funcs.cpp | 6 | ||||
-rw-r--r-- | core/math/math_funcs.h | 2 | ||||
-rw-r--r-- | core/os/os.cpp | 1 |
3 files changed, 3 insertions, 6 deletions
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 6a46b9fbe3..9f5a9c193a 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -30,7 +30,7 @@ #include "math_funcs.h" #include "core/os/os.h" -pcg32_random_t Math::default_pcg = { 1, PCG_DEFAULT_INC_64 }; +pcg32_random_t Math::default_pcg = { 12047754176567800795ULL, PCG_DEFAULT_INC_64 }; #define PHI 0x9e3779b9 @@ -51,9 +51,7 @@ void Math::seed(uint64_t x) { } void Math::randomize() { - - OS::Time time = OS::get_singleton()->get_time(); - seed(OS::get_singleton()->get_ticks_usec() * (time.hour + 1) * (time.min + 1) * (time.sec + 1) * rand()); // TODO: can be simplified. + seed(OS::get_singleton()->get_ticks_usec() * default_pcg.state + PCG_DEFAULT_INC_64); } uint32_t Math::rand() { diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 10426c9243..d71d9bd792 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -157,7 +157,7 @@ public: static uint32_t larger_prime(uint32_t p_val); - static void seed(uint64_t x = 0); + static void seed(uint64_t x); static void randomize(); static uint32_t rand_from_seed(uint64_t *seed); static uint32_t rand(); diff --git a/core/os/os.cpp b/core/os/os.cpp index ab03bb8016..e323e03829 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -507,7 +507,6 @@ OS::OS() { _render_thread_mode = RENDER_THREAD_SAFE; _allow_hidpi = true; - Math::seed(1234567); } OS::~OS() { |