RockGuitarist1
RockGuitarist1

Reputation: 115

Showing Multiple Numbers from RNG

What I am trying to do is create an RNG button that will generate 5 unique numbers between 1-99. This is what I have so far:

Private Sub GenerateButton_Click(sender As Object, e As EventArgs) Handles GenerateButton.Click
    Dim rand As New Random()
    Dim rememberset As New HashSet(Of Integer)
    Dim value As Integer

    While rememberset.Count < 6
        value = rand.Next(1, 99)
        If rememberset.Add(value) Then
            LotteryLabel.Text = value.ToString()
        End If
    End While
End Sub

Every time I click the generate button, I just get 1 number. I'm trying to get 5 to display in this format (1, 2, 3, 4, 5). Any ideas? Thanks.

Upvotes: 1

Views: 38

Answers (1)

Benjamin Beichler
Benjamin Beichler

Reputation: 26

Your LotteryLabel.Text is always set to the string of only one number ( I guess you will see only the last number)

You need to append the value: Easy (but maybe slow) solution should be

LotteryLabel.Text = LotteryLabel.Text & ", " & value.ToString()

Upvotes: 1

Related Questions