Skip to content

Instantly share code, notes, and snippets.

@abaez
Created October 30, 2013 16:33
Show Gist options
  • Save abaez/7235759 to your computer and use it in GitHub Desktop.
Save abaez/7235759 to your computer and use it in GitHub Desktop.
randomize an order of an array.
#!/usr/bin/env lua
function shuffle(tab)
-- allocation of the random array
local random_tab = {}
for i=1,#tab do
table.insert(random_tab, nil)
end
for i=#tab,1 do
random_tab[math.random(1,i)] = tab[i]
end
return random_tab
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment