Hi, so I’m trying to create an obby generator with random gamemodes, but im having issues getting a random number I keep running into limitations of the system.

math.random() work only with 32 Bit equivilent numbers, so I would only have a total of 4 billion unique seeds to generate between when using math.random(). :NextInteger() works with 64 bit equivilent numbers, which allows for over 18 quintillion unique seeds, so :NextInteger() would be the best choice when it comes to generating more unique seeds.

However instead of randomly generating between 18 quintillion unique numbers, Its overflowing well beyond the 64 bit integer limit. And after printing out (2^63) - 1 in the output, it is returning 9223372036854776000, with the known integer limit being 9223372036854775807. So when subtracting between the two numbers (9223372036854776000 - 9223372036854775807), I am getting a number well beyond the 64 bit integer limit, with the number roblox giving me being bigger by 193 digits.

This is the code I have to get a random seed between that limit

ob.IntRange = {-(2^63), (2^63) - 1}
function ob.newSeed()
return Random.new():NextInteger(ob.IntRange[1], ob.IntRange[2]);
end

You can say the same thing for Minecraft (another game that uses this number to generate seeds)
Is 18 quintillion different Minecraft seeds necessary for a game like this? No, but It keeps the game randomized with different combinations of biomes, structures, and mobs.

Roblox seems to have a big issue with calculating 2^63 - 1 with it instead giving a number outside the limit, causing the subtraction not to work.

In order to get the Answers I got, I had to shorten the number to where the numbers were different, which I subtracted 6000 - 5807.

Minecraft randomly picks a number and then creates the blocks.

Its random ranges from (-2^63 - 2^63 - 1), which is 18 quintillion.
Prior, it used to be up to 2^31.

Minecraft doesn’t store the seeds somewhere, it picks a number, and then creates a world using that number like with any world generator.

Either way, It should not matter how many unique seeds there are, and I’m not sure why it’s important or a big issue, Its just a number used to make something random.

Your problem is because the number is too big, so it does matter. I suggest taking it down under the limit. You are comparing your obby game generator to MINECRAFT, a game with millions of chunks, that’s huge.

You’re getting unexpected results because Luau doesn’t use real integers, it has a generic number type that is a 64-bit float. A float value can use the same number of bits as an int value, but it can represent a much larger range of numbers, with the downside being that higher numbers become less precise. For example, a 32-bit float at the number 33,554,432 has enough precision loss such that the next highest number it can represent is 33,554,436 (if Im understanding the Wikipedia article correctly).

I hope this helps. I’m not exactly sure what the main issue is in your post, other than the maximum number representable being higher than the 64-bit int limit when you thought otherwise.

Doing a little bit of more research, this would be reason.
Though, it isnt nessecarly Single-precision (The 32 Bit equivilent), but Double-precision (Which is 64 bit).

As an update to this, i figured out a way to properly use 2^63 with its precision loss:

ob.IntRange = {
-(2^63) + 1000, -- despite losing precision, -1000 is still accurate enough
(2^63) - 1000 -- it allows us to be within the 64 bit range without overflow
}
function ob.newSeed()
local n = Random.new():NextInteger(ob.IntRange[1], ob.IntRange[2]);
local a = math.floor(n / math.random(2^31 - 1));
return
end

While it is possible to get up to 18 quintilion seeds, its essentially picking the lower numbers for better precision, but in rare cases, it may pick a seed at around 2^63 if it can. (But thats a 1 in 2.4 Billion chance of occuring), I’ll probably modify it to be more agressive (as in pick numbers for long ranges) with its outcome.