From c45f243d1578b920c50d8da1158631998c0ed988 Mon Sep 17 00:00:00 2001 From: duncathan Date: Sun, 15 Sep 2019 17:38:09 -0600 Subject: [PATCH] use a proper hashing algorithm for seeds like i should've from the start --- src/conf.lua | 1 - src/main.lua | 1 + src/randomizer.lua | 14 ++++++-------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/conf.lua b/src/conf.lua index cba8b7c..94fbd09 100644 --- a/src/conf.lua +++ b/src/conf.lua @@ -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 diff --git a/src/main.lua b/src/main.lua index 8765060..67935ce 100644 --- a/src/main.lua +++ b/src/main.lua @@ -7,6 +7,7 @@ _ = require 'lib.moses' lf = love.filesystem lg = love.graphics +ld = love.data U = require 'util' diff --git a/src/randomizer.lua b/src/randomizer.lua index 03f6cd4..d22d40f 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -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