Skip to content

Commit

Permalink
Merge pull request #8441 from tagcup/seed_fix
Browse files Browse the repository at this point in the history
Fix PRNG randomization.
  • Loading branch information
akien-mga authored Apr 17, 2017
2 parents 24b2186 + ceb699f commit 7088d9e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
6 changes: 2 additions & 4 deletions core/math/math_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion core/math/math_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class Math {

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();
Expand Down
1 change: 0 additions & 1 deletion core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ OS::OS() {
_render_thread_mode = RENDER_THREAD_SAFE;

_allow_hidpi = true;
Math::seed(1234567);
}

OS::~OS() {
Expand Down

0 comments on commit 7088d9e

Please sign in to comment.