Last active
September 26, 2024 21:09
-
-
Save Uradamus/10323382 to your computer and use it in GitHub Desktop.
A simple array shuffle function for Lua implementing the Fisher-Yates shuffle.
This file contains 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
function shuffle(tbl) | |
for i = #tbl, 2, -1 do | |
local j = math.random(i) | |
tbl[i], tbl[j] = tbl[j], tbl[i] | |
end | |
return tbl | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh, nice! They explained it way better than you did! Shoulda posted that first. Thanks!