Question about randomseed

I have some strange problem with randomseed.
It works ok on simulator and most of the phones, but on several android something strange happens.
Let’s for example use this simple code with empty project:
math.randomseed(156)
timer.performWithDelay(5000, function()
print(math.random(100))
print(math.random(100))
print(math.random(100))
end)
timer.performWithDelay(10000, function()
math.randomseed(156)
print(math.random(100))
print(math.random(100))
print(math.random(100))
end)
On an emulator and some phones everything is ok and I have 3 random numbers, everytime same 3 numbers.
But on Samsung with oneUI 2.5 or Xiaomi with Miui 11 I have the same numbers on the second timer and different on first with every app restart.
So is this ok that I can’t use randomseed for static results when needed on some phones? Or I should do it somehow differently?
This needed for pick the same random positions in the table for the same specific data in the app.

Lua’s implementation of math.random() varies per platform.

If you need a pseudorandom number generator that will work the same across all platforms, then you’ll need a different implementation, like this one that I wrote:

Do note that Lua’s implementation runs faster, so you should only use this for when you need guaranteed seed based pseudorandom number generation across platforms.

3 Likes