Skip to content

Instantly share code, notes, and snippets.

@rangercyh
Last active April 12, 2018 06:29
Show Gist options
  • Save rangercyh/5819820 to your computer and use it in GitHub Desktop.
Save rangercyh/5819820 to your computer and use it in GitHub Desktop.
fisher_yates_shuffe algorithm
--Fisher_Yates_Shuff随机算法
local function shuffarray_fisher_yates(num)
local rand_seq = {}
for i = num, 1, -1 do
local idx = math.random(i)
local temp = rand_seq[i] or i
rand_seq[i] = (rand_seq[idx] or idx)
rand_seq[idx] = temp
end
return rand_seq
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment