Skip to content

Instantly share code, notes, and snippets.

@Uradamus
Last active November 3, 2023 09:39
Show Gist options
  • Save Uradamus/10323382 to your computer and use it in GitHub Desktop.
Save Uradamus/10323382 to your computer and use it in GitHub Desktop.
A simple array shuffle function for Lua implementing the Fisher-Yates shuffle.
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
@asbestosbill
Copy link

Oh, nice! They explained it way better than you did! Shoulda posted that first. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment