Help..What am I doing wrong...
I am trying to create random unique numbers in the range of 1-49 and in ascending order..Now this part I have got and it works perfectly, now the problem I have is every now and again(I'm talking maybe25-30 clicks of the button later) a duplicate number will appear and then it will run perfectly again.Can anyone tell me where I'm going wrong ?
Here is my code....
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim intarray(5) As Integer
Dim i As Integer
Dim j As Integer
Dim a As Integer
Dim b As Integer
Dim repeated As Boolean
Dim tempnum As Integer
Randomize()
For i = 0 To 5
intarray(i) = ((Rnd() * 48) + 1)
Next
For i = 0 To 5
If i > 0 Then
For j = 0 To i - 1
If intarray(i) = intarray(j) Then
intarray(i) = ((Rnd() * 48) + 1)
repeated = False
End If
Next j
End If
Next i
For a = LBound(intarray) To (UBound(intarray) - 1)
For b = (a + 1) To UBound(intarray)
If intarray(a) > intarray(b) Then
tempnum = intarray(a)
intarray(a) = intarray(b)
intarray(b) = tempnum
End If
Next b
Next a
Label1.Text = intarray(0)
Label2.Text = intarray(1)
Label3.Text = intarray(2)
Label4.Text = intarray(3)
Label5.Text = intarray(4)
Label6.Text = intarray(5)
|