1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Fix PRNG randomization.

PCG32 doesn't like small seeds, which leads to zero random values (prior to #7532, zero values were handled as special cases).

Use a large default seed, and also add a shift in Math::randomize.

Fixes #8423.
This commit is contained in:
Ferenc Arn
2017-04-17 12:50:31 -05:00
parent 6f9ec3acfc
commit ceb699f5ec
3 changed files with 3 additions and 6 deletions

View File

@@ -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() {