as the title says, i have an array of 20 integers. Each time i generate a new random number, i want to check if it is already contained in the array. If the number exists in the array, i want to re-generate a random number and re-check the array from start again. In the end, my array of 20 integers should contain all unique values between 7 to 30. I have created a perfect code mess doing this. Appreciate some help from the experts here. Thanks so much.
Dim Low, High, tmpNo As Double
Dim myarray(20) As Integer
Dim i, x As Integer
Low = 7
High = 30
i = 0
x = 0
For i = 0 To 19
tmpno = Int((High - Low + 1) * Rnd() + Low)
If i = 0 Then
myarray(i) = tmpno
tmpno = Int((High - Low + 1) * Rnd() + Low)
End If
For x = 0 To Len(i)
If tmpno = myarray(x) Then
tmpno = Int((High - Low + 1) * Rnd() + Low)
x = 0
Else
If myarray(x + 1) = 0 Then
myarray(x + 1) = tmpno
tmpno = Int((High - Low + 1) * Rnd() + Low)
x = 0
End If
End If
Next
Next