1
0
mirror of https://github.com/veden/Rampant.git synced 2024-12-26 20:54:12 +02:00

FACTO-130: Fixed the xor random number generator period being cut in half

This commit is contained in:
Aaron Veden 2022-05-01 21:38:38 -07:00
parent d1cc7e10bb
commit 81ea0f65a7
No known key found for this signature in database
GPG Key ID: FF5990B1C6DD3F84
2 changed files with 7 additions and 6 deletions

View File

@ -5,6 +5,8 @@ Version: 3.1.0
- Migration and siege groups now try to avoid chunks with existing enemy structures - Migration and siege groups now try to avoid chunks with existing enemy structures
Tweaks: Tweaks:
- Runtime number generator just uses the map seed now - 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 Version: 3.0.3

View File

@ -73,14 +73,13 @@ function mathUtils.xorRandom(state)
local lshift = bit32.lshift local lshift = bit32.lshift
local rshift = bit32.rshift local rshift = bit32.rshift
state = state + 21594771 local seed = state + 32685453
return function() return function()
state = xor(state, lshift(state, 13)) seed = xor(seed, lshift(seed, 13))
state = xor(state, rshift(state, 17)) seed = xor(seed, rshift(seed, 17))
state = xor(state, lshift(state, 5)) seed = xor(seed, lshift(seed, 5))
state = state % 2147483647 return seed * 2.32830643654e-10 -- 2.32830643654e-10 = 1 / 2^32, 2.32830643708e-10 = 1 / ((2^32)-1)
return state * 4.65661287525e-10
end end
end end