以前写的,参数 随机数个数 同时也是 随机数上限 返回long数组
Function GetNoReArray(ub&) As Long()
Dim i As Long
Dim k As Long
Dim it() As Long
ReDim it(ub - 1) As Long
Dim n As Long
Randomize
Dim h As Long
For i = 0 To ub - 1
h = (Rnd() * ub)
For k = 0 To i
If h = it(k) Then
n = 1: Exit For
End If
Next
If n = 1 Then
i = i - 1
Else
it(i) = h
End If
n = 0
Next
' For i = 0 To UBound(it)
' Debug.Print it(i)
' Next
'
GetNoReArray = it
End Function