Created
October 30, 2013 16:33
-
-
Save abaez/7235759 to your computer and use it in GitHub Desktop.
randomize an order of an array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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