Making a reversible RNG

Hello! So a while back I found this very fun website called the library of babel (check it out https://libraryofbabel.info/ I thought it would be cool to make a roblox game based off of a similar concept.

Essentially, the library contains theoretically infinite rooms each with many books. Each book’s contents are simply a random permutation (a permutation is a just another words for combination where order matters) of the basic English characters. So, for the most part, all you’ll find is random characters scribbled together with no meaning. However, there is the rare occurrence that you my find a word, or even a phrase.

Another cool part of the game is the search feature, where you can search the library of a words or phrase. This works by somehow reversing the RNG used to generate the text to find out the exact location of the book.

Currently, I haven’t been able to find a way to make a reversible RNG, especially one that has multiple inputs. Currently I have been using Roblox’s built in noise functions to generate the text, but I don’t see a way to easily reverse that. I really believe that a search feature would help enhance the game, so if any of you have any knowledge about reversible RNGs or good algorithms, please tell me.

Thanks for taking the time to read this article. I have linked the random number generator I created.

local function GenerateRandomNumber(seed,Params,lowestValue,highestValue)

	local Primes = {
		5231,5233,5237,5261,5273,5279,5281,5297,5303,5309,5323,5333,5347,5351,5381,5387,5393,5399,5407,5413,5417,5419,5431,5437,5441,5443,5449,5471,5477,5479,5483,5501,5503,5507,5519,5521,5527,5531,5557,5563,5569,5573,5581,5591,5623,5639,5641,5647,5651,5653,5657,5659,5669,5683,5689,5693,5701,5711,5717,5737,5741,5743,5749,5779,5783,5791,5801,5807,5813,5821,5827,5839,5843,5849,5851,5857,5861,5867,5869,5879,5881,5897,5903,5923,5927,5939,5953,5981,5987,6007,6011,6029,6037,6043,6047,6053,6067,6073,6079,6089,6091,6101,6113,6121,6131,6133,6143,6151,6163,6173,6197,6199,6203,6211,6217,6221,6229,6247,6257,6263,6269,6271,6277,6287,6299,6301,6311,6317,6323,6329,6337,6343,6353,6359,6361,6367,6373,6379,6389,6397,6421,6427,6449,6451,6469,6473,6481,6491,6521,6529,6547,6551,6553,6563,6569,6571,6577,6581,6599,6607,6619,6637,6653,6659,6661,6673,6679,6689,6691,6701,6703,6709,6719,6733,6737,6761,6763,6779,6781,6791,6793,6803,6823,6827,6829,6833,6841,6857,6863,6869,6871,6883,6899,6907,6911,6917,6947,6949,6959,6961,6967,6971,6977,6983,6991,6997,7001,7013,7019,7027,7039,7043,7057,7069,7079,7103,7109,7121,7127,7129,7151,7159,7177,7187,7193,7207,7211,7213,7219,7229,7237,7243,7247,7253,7283,7297,7307,7309,7321,7331,7333,7349,7351,7369,7393,7411,7417,7433,7451,7457,7459,7477,7481,7487,7489,7499,7507,7517,7523,7529,7537,7541,7547,7549,7559,7561,7573,7577,7583,7589,7591,7603,7607,7621,7639,7643,7649,7669,7673,7681,7687,7691,7699,7703,7717,7723,7727,7741,7753,7757,7759,7789,7793,7817,7823,7829,7841,7853,7867,7873,7877,7879,7883,7901,7907,7919
	}

	local Output = 0

	for i = 1, #Params do
		local noise = math.round(math.noise(Params[i]*math.sqrt(2), seed*math.sqrt(2), seed*math.sqrt(3))*99999)
		Output = Output+(noise*Primes[i])
	end

	Output = (Output % (highestValue - lowestValue + 1)) + lowestValue

	return Output
end
1 Like