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.modules.audio = false
t.modules.data = false
t.modules.joystick = false
t.modules.physics = false
t.modules.sound = false

View file

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

View file

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