You are here: DEVPPL Forum Programming Visual Basic Forum
NOTIFICATIONS
54.102
MEMBERS
15.693
TOPICS
62.279
POSTS
  562
FLASH GAMES
7.740
TUTORIALS
 

Login

E-mail:
Password:

Little help with homework please

0

Loading

Little help with homework please

Postby Pfm » Fri Oct 07, 2011 5:04 am

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: 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

Little help with homework please - Sponsored results

Sponsored results

Login to get rid of ads

 

goldmedal
1

Loading

Re: Little help with homework please

Postby Ciiure » Fri Nov 18, 2011 9:31 pm

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.
Ciiure
 
Reputation: 1
Posts: 5
Joined: Fri Nov 18, 2011 8:45 pm
Highscores: 0
Arcade winning challenges: 0
goldmedal
1

Loading

Re: Little help with homework please

Postby Ciiure » Fri Nov 18, 2011 9:31 pm

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.
Ciiure
 
Reputation: 1
Posts: 5
Joined: Fri Nov 18, 2011 8:45 pm
Highscores: 0
Arcade winning challenges: 0
^ Back to Top