Public Class Form1
'The checkList array is used to check off which numbers
'have already been randomly picked.
Private checkList(20) As Boolean
'The counter is used to show how many times it took
'for all numbers to be randomly picked.
Private counter As Integer = 0
'The track variable tells me when I should end the while....loop
'I could have just used a long if or select case, but it just
'seems easier this way.
Private track As Integer = 0
'This value of this variable (true|false) determines
'whether the While....Loop continues running or not.
Private continueLoop As Boolean = True
'I need these variables to access the Random class
'so the program will generate a random number.
Dim generator As New Random
Dim randomValue As Integer
Private Sub cmdRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRun.Click
Dim i As Integer = 0
'This resets the checkList array.
For i = 0 To i < 19 Step 1
checkList(i) = False
Next i
'These three lines are just resetting the variables
'in case the program ran once before.
counter = 0
track = 0
continueLoop = True
'The loop starts and will end when the continueLoop is set to false.
While (continueLoop)
'When the track variable reaches 19 in the array index (0-19)
'for a total of 20 indexes or more simply put 20 numbers, then
'the continueLoop will be set to false. UPDATE: I seen a
'mistake on my part. The counter variable will get incremented
'by one, so the continueLoop variable is pointless, but since
'it is in there, then I'll leave it in. I used Exit While
'so the variable counter will not get incremented.
If (track = 19) Then
continueLoop = False
Exit While
End If
'This static sub procedure is supposed to sync the generator variable
'with the cpu clock to help the program generate better random values,
'instead of maybe some sort of random pattern.
Randomize()
'randomValue holds a random value of (1-20).
randomValue = generator.Next(1, 20)
'Depending on what number get randomly selected, is what
'case or option will get selected.
Select Case randomValue
Case 1
If (checkList(0) = True) Then
'has already been populated
track += 1
Else
checkList(0) = True
End If
Case 2
If (checkList(1) = True) Then
'has already been populated
track += 1
Else
checkList(1) = True
End If
Case 3
If (checkList(2) = True) Then
'has already been populated
track += 1
Else
checkList(2) = True
End If
Case 4
If (checkList(3) = True) Then
'has already been populated
track += 1
Else
checkList(3) = True
End If
Case 5
If (checkList(4) = True) Then
'has already been populated
track += 1
Else
checkList(4) = True
End If
Case 6
If (checkList(5) = True) Then
'has already been populated
track += 1
Else
checkList(5) = True
End If
Case 7
If (checkList(6) = True) Then
'has already been populated
track += 1
Else
checkList(6) = True
End If
Case 8
If (checkList(7) = True) Then
'has already been populated
track += 1
Else
checkList(7) = True
End If
Case 9
If (checkList(8) = True) Then
'has already been populated
track += 1
Else
checkList(8) = True
End If
Case 10
If (checkList(9) = True) Then
'has already been populated
track += 1
Else
checkList(9) = True
End If
Case 11
If (checkList(10) = True) Then
'has already been populated
track += 1
Else
checkList(10) = True
End If
Case 12
If (checkList(11) = True) Then
'has already been populated
track += 1
Else
checkList(11) = True
End If
Case 13
If (checkList(12) = True) Then
'has already been populated
track += 1
Else
checkList(12) = True
End If
Case 14
If (checkList(13) = True) Then
'has already been populated
track += 1
Else
checkList(13) = True
End If
Case 15
If (checkList(14) = True) Then
'has already been populated
track += 1
Else
checkList(14) = True
End If
Case 16
If (checkList(15) = True) Then
'has already been populated
track += 1
Else
checkList(15) = True
End If
Case 17
If (checkList(16) = True) Then
'has already been populated
track += 1
Else
checkList(16) = True
End If
Case 18
If (checkList(17) = True) Then
'has already been populated
track += 1
Else
checkList(17) = True
End If
Case 19
If (checkList(18) = True) Then
'has already been populated
track += 1
Else
checkList(18) = True
End If
Case 20
If (checkList(19) = True) Then
'has already been populated
track += 1
Else
checkList(19) = True
End If
End Select
counter = counter + 1
End While
txtNumOfChances.Text = counter
txtProbability.Text = 20 / counter
End Sub
End Class