Hello everyone,
I have a little problem that drove me crazy I can't figure it out, I spent hours searching the Web but in vain. I hope that you can help with it. The program must generate 6 unique random numbers but when I click display numbers sometimes it gives me 6 unique numbers and sometimes I get duplicate numbers. I will add the code I have so far and I hope that you can help me out.
Code:Public Class frmMain Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click ' close the application Me.Close() End Sub Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click Dim intRandom1 As Integer Dim intRandom2 As Integer Dim intRandom3 As Integer Dim intRandom4 As Integer Dim intRandom5 As Integer Dim intRandom6 As Integer Dim randomGenerator As New Random ' generate random integers intRandom1 = randomGenerator.Next(1, 55) intRandom2 = randomGenerator.Next(1, 55) intRandom3 = randomGenerator.Next(1, 55) intRandom4 = randomGenerator.Next(1, 55) intRandom5 = randomGenerator.Next(1, 55) intRandom6 = randomGenerator.Next(1, 55) ' display integers lblNumbers.Text = Convert.ToString(intRandom1) & " " & Convert.ToString(intRandom2) & " " & Convert.ToString(intRandom3) & " " & Convert.ToString(intRandom4) & " " & Convert.ToString(intRandom5) & " " & Convert.ToString(intRandom6) End Sub End Class
Thank you so much




Reply With Quote