I really didn’t want to have to make a Devforum post, but after an entire day of having no idea what to do this is practically my last resort.
The title might be slightly confusing, so let me elaborate:
I’m currently working on a Roblox port of the website Library of Babel. It’s basically a website that contains 10^4677 randomly generated books (Practically anything you can write in English, it’s on this website, including this Devforum page Here). It’s able to contain this amount of books as instead of storing them, they can be retrieved by using a Random Number Generator, and using the Hex, Wall, Shelf, and Volume as a seed, then using that to randomly generate 3200 characters for 410 pages.
I already got the main part - randomly generating the book’s title and contents with a Linear Congruential Generator, but I’m missing one of the core features of the Library of Babel- The search feature.
I’m pretty sure the search feature in the Library Of Babel works by getting the seed of the book that would generate that exact line of text and giving you the address of that book.
Problem is, I have NO idea how to do this in Lua (or any other language for that matter), though I know its possible, as the Library Of Babel is a living testimony to this.
The current code I’m using to generate Random Numbers is:
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 / 0x10000
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
function lcg(s, r)
local temp = {}
setmetatable(temp, linear_congruential_generator)
temp.a, temp.c, temp.m = 1103515245, 12345, 0x100000000 --from Ansi C
if r then
if r == 'nr' then temp.a, temp.c, temp.m = 1664525, 1013904223, 0x100000000 --from Numerical Recipes.
elseif r == 'mvc' then temp.a, temp.c, temp.m = 214013, 2531011, 0x100000000 end--from MVC
end
temp:randomseed(s)
return temp
end
I’m using randomlua for this, yet I’m only using the LCG, not the MWC or The twister
Is there anyway I could feed a function an array of results, and have it return a seed that would result in those exact results, or is there already an open-sourced random number generator for Lua that can already do something like that?
If you need me to elaborate more, just tell me. It’s a really confusing and specific question, so I understand