I'm currently working on a Lua port of the Library Of Babel.
To my knowledge, it works by randomly generating the title and book by using the Hex, Bookshelf, Shelf, and Volume numbers. To implement this in Lua, I was using randomlua, because Lua's built-in random API wasn't working well for me.
My only problem with it so far is that it doesn't allow me to reverse a result from the LCG to get the seed, which I need to do to implement searching for books. I'm not that intelligent when it comes to math like this, so I have no idea where to start.
This is the code for generating random numbers:
linear_congruential_generator = {}
linear_congruential_generator.__index = linear_congruential_generator
function linear_congruential_generator:random(a, b)
local y = (self.a * self.x + self.c) % self.m
self.x = y
if not a then return y / 0x100000000
elseif not b then
if a == 0 then return y
else return 1 + (y % a) end
else
return a + (y % (b - a + 1))
end
end
I have absolutely no idea how I could reverse the function to make it return a seed where that result occurs. Any help on this is greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire