randoming a table Corona SDK / Lua
snippet in lua

randoming a table Corona SDK / Lua

user5183

local M, N, tNonFinal, tFinal = 500, 20, {}, {}

math.randomseed( os.time() )

for i = 1, N, 1 do
    local iRandom = math.random(1, M)
    while tNonFinal[iRandom] do
        iRandom = math.random(1, M)
    end
    table.insert( tNonFinal, iRandom, true )
    tFinal[i] = iRandom
end