I’ve made a simple function which selects 32 random numbers. On the sim it works fine, but on iOS and Android it always returns the same 32 numbers in the same order, even when a time is passed in to math.randomseed().
I’ve simplified my function, and tested this on a device to confirm there was nothing else affecting the random numbers:
--get time in seconds local now = os.time() --and milliseconds since app was opened local millis = system.getTimer() --concatenate to make a longer unique number local newSeed = tostring(now)..tostring(millis) --convert tonumber just to make sure randomseed accepts it --this seems to round to an int which is fine as number should still be unique newSeed = tonumber(newSeed) --set randomseed math.randomseed(tonumber(newSeed)) --select 32 random numbers from 1 to 100 local maxRandom = 100 for i = 1, 32 do local ranNum = math.random(1, maxRandom) print(ranNum) end
On iOS I get the same result every time I restart the app:
25 2 39 42 7 100 49 77 4 4 94 89 60 48 84 19 74 12 70 36 64 91 30 27 38 55 1 100 2 85 86 47
Android gets different results to iOS, but again will always generate the same pattern each time the app is restarted.
I’m using Enterprise build 2886. Is there a known issue with math.randomseed, or have I made a mistake somewhere that I’m overlooking?
