[ create a new paste ] login | about

Link: http://codepad.org/CtBsuCrA    [ raw code | output | fork ]

Lua, pasted on Aug 20:
function copy(tab)
    local ret = {}
    for _,v in pairs(tab) do 
        table.insert(ret, v)
    end
    return ret
end
math.randomseed(os.time())
local based_array = {1, 2, 3, 4, 5}
local used = copy(based_array)
function __sort(tab)
    local i= math.random(#tab)
    local selected = tab[i]
    table.remove(tab, i)
    tab = copy(tab)
    if type(tab) ~= "table"  then
        tab = copy(based_array)
    end
    return selected 
end

for i=1, #used do 
    print(__sort(used))
end


Output:
1
2
3
4
5
4
2
3
5
1


Create a new paste based on this one


Comments: