Fisher_Yates_Shuff
2229 단어 랜덤 알고리즘
- --Fisher_Yates_Shuff
- function ShuffArray_Fisher_Yates(nTotalNum, nNum)
- local tbTemp = {}
- if nNum == 0 then
- return tbTemp
- end
- if nNum > nTotalNum then
- nNum = nTotalNum
- end
-
- for i = 1, nTotalNum do
- tbTemp[i] = i
- end
-
- local tbRandSeq = {}
- for i = 1, nNum do
- local nLocal = math.random(#tbTemp)
- tbRandSeq[i] = tbTemp[nLocal]
- table.remove(tbTemp, nLocal)
- end
- return tbRandSeq
- end