| You are here: DEVPPL ‹ Forum ‹ Programming ‹ Visual Basic Forum |
NOTIFICATIONS
|
|
|||||||||||||||
Login |
Little help with homework please
2 posts
• Page 1 of 1
0
Little help with homework please
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.
Thank you so much
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: Select all
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
- Pfm
- Reputation: 0
- Posts: 3
- Joined: Thu Sep 08, 2011 2:17 pm
- Highscores: 0
- Arcade winning challenges: 0
1
Re: Little help with homework please
Its because random function picks random numbers and sometimes it can give you same number.
you could use some sort of check function such as if number1 is same as any other number then repick number.
you could use some sort of check function such as if number1 is same as any other number then repick number.
- Ciiure
- Reputation: 1
- Posts: 5
- Joined: Fri Nov 18, 2011 8:45 pm
- Highscores: 0
- Arcade winning challenges: 0
1
Re: Little help with homework please
Its because random function picks random numbers and sometimes it can give you same number.
you could use some sort of check function such as if number1 is same as any other number then repick number.
you could use some sort of check function such as if number1 is same as any other number then repick number.
- Ciiure
- Reputation: 1
- Posts: 5
- Joined: Fri Nov 18, 2011 8:45 pm
- Highscores: 0
- Arcade winning challenges: 0
|
|