''生成一组随机数序列,可以指定重复率 [ 参数: 待填充数组, 数据数量, 重复率% ]
Sub RanSequence(Result() As Long, ByVal ItemCount As Long, Optional ByVal Repetition As Byte = 0)
If ItemCount < 2 Or Repetition > 100 Then Exit Sub
ReDim Result(0 To ItemCount - 1): If UBound(Result) < 0 Then Exit Sub
Dim i As Long, k As Long
k = Fix(((100# - Repetition) / 100#) * ItemCount) '不重复的数量
For i = 0 To k - 1: Result(i) = i: Next '不重复的原始数据
For i = k To ItemCount - 1 '附加重复的原始数据(如果有重复率)
Result(i) = Fix(k * Rnd)
Next
Randomize '把数组打乱顺序
For i = ItemCount - 1 To 1 Step -1
k = Fix(i * Rnd)
Result(i) = Result(i) Xor Result(k)
Result(k) = Result(i) Xor Result(k)
Result(i) = Result(i) Xor Result(k)
Next
End Sub