Last active
April 12, 2018 06:29
-
-
Save rangercyh/5819820 to your computer and use it in GitHub Desktop.
fisher_yates_shuffe algorithm
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
--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