I have a pool of ten numbers, I need to test that none are identical. each number in an element of an array. The numbers are random, but the problem I run into is that sometimes they are identical numbers. How can I get around this?
MrBeta
Printable View
I have a pool of ten numbers, I need to test that none are identical. each number in an element of an array. The numbers are random, but the problem I run into is that sometimes they are identical numbers. How can I get around this?
MrBeta
Try this:
Hope this is what you were looking for.Code:Dim aiNumbers(1 To 10) As Integer
Dim iTemp As Integer
Dim iElement As Integer
Dim idx As Integer
Randomize
Do
iTemp = Rnd(100) * 100
For idx = LBound(aiNumbers) To UBound(aiNumbers) Step 1
If iTemp = aiNumbers(idx) Then
iTemp = -1
Exit For
End If
Next idx
If iTemp <> -1 Then
iElement = iElement + 1
aiNumbers(iElement) = iTemp
Debug.Print aiNumbers(iElement)
End If
Loop While iElement < 10