Integer overflow with math.randomseed?

For starters, what I believe I’ve found here is either a bug or something that just isn’t well documented. As the title states, any number over the 32 bit integer limit will produce the same random results as -2,147,483,648 when a random seed is set via math.randomseed.

The weird part about this is that the Random library is not affected by this at all. Here’s some code to reproduce the behavior:

math.randomseed(2147483648) -- any number over the 32 bit integer limit will do

for i = 1, 5 do
     print(math.random(1,5))
end

-- [OUTPUT]:
-- 1, 1, 1, 4, 5 

local Rand = Random.new(-2147483648)

for i = 1, 5 do
     print(Rand:NextInteger(1,5))
end

-- [OUTPUT]:
-- 1, 1, 1, 4, 5 

Is this behavior defined anywhere? I checked the wiki for both Random.new and math.randomseed and neither say anything about the limit for seeds but it’s pretty obvious there is one specifically for randomseed.

Just as one last confirmation that I’m not a lunatic, here’s the same code with different random results using the random library with the same seed as before:

local Rand = Random.new(2147483648)

for i = 1, 5 do
     print(Rand:NextInteger(1,5))
end

-- [OUTPUT]:
-- 4, 4, 5, 2, 3

Sorry if this is the wrong category for this type of thing, I don’t have access to post in #platform-feedback:engine-bugs

1 Like