diff --git a/changelog.txt b/changelog.txt index e882043..a617719 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,6 +5,8 @@ Version: 3.1.0 - Migration and siege groups now try to avoid chunks with existing enemy structures Tweaks: - Runtime number generator just uses the map seed now + Bugfixes: + - Fixed the period of the xor number generator being cut in half --------------------------------------------------------------------------------------------------- Version: 3.0.3 diff --git a/libs/MathUtils.lua b/libs/MathUtils.lua index 0320727..8fe29f7 100644 --- a/libs/MathUtils.lua +++ b/libs/MathUtils.lua @@ -73,14 +73,13 @@ function mathUtils.xorRandom(state) local lshift = bit32.lshift local rshift = bit32.rshift - state = state + 21594771 + local seed = state + 32685453 return function() - state = xor(state, lshift(state, 13)) - state = xor(state, rshift(state, 17)) - state = xor(state, lshift(state, 5)) - state = state % 2147483647 - return state * 4.65661287525e-10 + seed = xor(seed, lshift(seed, 13)) + seed = xor(seed, rshift(seed, 17)) + seed = xor(seed, lshift(seed, 5)) + return seed * 2.32830643654e-10 -- 2.32830643654e-10 = 1 / 2^32, 2.32830643708e-10 = 1 / ((2^32)-1) end end