简单的洗牌算法
shuffle={}; local this=shuffle; local list={1,9,2,3,4,5,6,7,8,11,13}; function randomSort(list,value) table.insert(list,value); local temp=0; for i=#list,1,-1 do local randomNum=math.floor(math.random(1,i)); temp=list[i]; list[i]=list[randomNum]; list[randomNum]=temp; end end function println() print("--------------------------"); local s=""; for k,v in ipairs(list) do s=s..v.." "; end print(s); end randomSort(list,100); println() randomSort(list,999); println()
评论