7,785
社区成员




Private Sub Command1_Click()
Debug.Print GetRndNumber()
End Sub
Private Function GetRndNumber() As String
Const N = 9999
Static i As Long
Static a(N) As Long
Dim r As Long
If i = 0 Then
For i = 0 To N
a(i) = i
Next
i = 0
End If
Randomize
r = Int((N - i + 1) * Rnd + i)
GetRndNumber = Format(a(r), "0000")
a(r) = a(i)
i = i + 1
If i > N Then i = 0 '全部随机数用完就重新来过
End Function
Private Sub Form_Load()
Dim a()
Dim bool As Boolean
Dim s As Integer, i As Integer, j As Integer, k As Integer
ReDim Preserve a(0)
a(0) = XX
For i = 1 To 50
bool = False
s = XX
For j = 0 To UBound(a)
If s = a(j) Then
bool = True
Exit For
End If
Next
If bool = False Then
k = k + 1
ReDim Preserve a(k)
a(k) = s
Debug.Print s
End If
Next
End Sub
Private Function XX() As Integer
XX = Int((9000) * Rnd + 1000)
End Function