- -- 打乱数组元素
- --start:起始位置
- --endi:结束位置
- function random_array(arr,start,endi)
- start = start or 1
- endi = endi or #arr-1
- local tmp, index
- for i=start, endi do
- index = math.random(start, endi)
- if i ~= index then
- tmp = arr[index]
- arr[index] = arr[i]
- arr[i] = tmp
- end
- end
- end
复制代码
|