use a proper hashing algorithm for seeds like i should've from the start

This commit is contained in:
duncathan 2019-09-15 17:38:09 -06:00
parent 6afa0ad2e5
commit c45f243d15
3 changed files with 7 additions and 9 deletions

View file

@ -17,7 +17,6 @@ function love.conf(t)
t.gammacorrect = false t.gammacorrect = false
t.modules.audio = false t.modules.audio = false
t.modules.data = false
t.modules.joystick = false t.modules.joystick = false
t.modules.physics = false t.modules.physics = false
t.modules.sound = false t.modules.sound = false

View file

@ -7,6 +7,7 @@ _ = require 'lib.moses'
lf = love.filesystem lf = love.filesystem
lg = love.graphics lg = love.graphics
ld = love.data
U = require 'util' U = require 'util'

View file

@ -93,14 +93,12 @@ function C:_mountDirectory(path)
end end
function C:_seedRngesus() function C:_seedRngesus()
local seed = self.customseed or os.time() local seedstring = self.customseed or tostring(os.time())
seed = tonumber(seed) or tonumber(seed, 36) -- convert alphanumeric strings to numbers local seed = ld.encode('string', 'hex', ld.hash('sha256', seedstring))
local seedstring = self.customseed or tostring(seed) local s1 = tonumber(seed:sub(-8, -1), 16) -- first 32 bits (from right)
if seed == nil then local s2 = tonumber(seed:sub(-16, -9), 16) -- next 32 bits
seed = os.time()
seedstring = ('%d ("%s" was invalid)'):format(seed, self.customseed) love.math.setRandomSeed(s1, s2)
end
love.math.setRandomSeed(seed)
logNotice(('Offering seed "%s" to RNGesus' ):format(seedstring)) logNotice(('Offering seed "%s" to RNGesus' ):format(seedstring))
return seedstring return seedstring