-
[2005]
In this simple Lottery simulation, how do I ensure that a number is not generated twice? I am assuming I need to search the array to verify that there are no equal values but how? Thanks much.
Public Class Lottery
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim counter As Integer = 0
Dim y As Integer
Dim instance As New Random()
Dim myArray(5) As Integer
While counter < myArray.Length
y = instance.Next(1, 37)
myArray(counter) = y
counter = counter + 1
TextBox1.Text = TextBox1.Text & y & (" ")
End While
End Sub
-
Re: [2005]
try this code
Code:
dim counter as integer = 0
dim numberArray = new arraylist()
dim i, y as integer
dim instance as new Random()
while numberArray.count < 6
y = instance.Next(1, 37)
if numberArray.indexOf(y) > -1 then continue while
numberArray.Add(y)
end while
-
Re: [2005]
In a lottery draw what do they do when they pick a number? Do they put it back so it can be picked again? No, they remove it from the pool so they know that every selection will be unique. You should do the same thing.
http://www.vbforums.com/showthread.php?t=393023
Also, please provide a descriptive title for your threads.