Dim c As Collection
'初始化,定义产生随机数的最小值和最大值
Public Sub Init(min As Integer, max As Integer)
Set c = New Collection
Dim i As Integer
For i = min To max
c.Add i
Next
End Sub
'产生不重复的随机数
Public Function RandomNext() As Integer
Dim i As Integer
Dim number As Integer, upperbound As Integer
upperbound = c.Count
If upperbound > 0 Then
number = Int((upperbound) * Rnd + 1)
RandomNext = CInt(c.Item(number))
c.Remove (number)
Else
RandomNext = 0
End If
End Function
Private Sub Class_Terminate()
Set c = Nothing
End Sub