我目前正在开发Library Of Babel的 Lua 端口。
据我所知,它通过使用十六进制、书架、书架和卷号随机生成标题和书籍来工作。为了在 Lua 中实现这一点,我使用了 randomlua,因为 Lua 的内置随机 API 对我来说效果不佳。
到目前为止,我唯一的问题是它不允许我从 LCG 反转结果来获取种子,我需要这样做来实现搜索书籍。当谈到这样的数学时,我没有那么聪明,所以我不知道从哪里开始。
这是生成随机数的代码:
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
我完全不知道如何反转函数以使其返回发生该结果的种子。非常感谢您对此的任何帮助。
这就是我计算页面标题和内容的方式:
local charset = {} do -- [0-9a-zA-Z]
for c = 48, 57 do table.insert(charset, string.char(c)) end
for c = 65, 90 do table.insert(charset, string.char(c)) end
for c = 97, 122 do table.insert(charset, string.char(c)) end
table.insert(charset," ")
end
function randomString(length)
if not length or length <= 0 then return '' end
return randomString(length - 1) .. charset[generator:random(1, #charset)]
end
标题为 8 个字符,内容为 3200 个字符。