trying to not allow doubles if there is a double For example, if the app returns two random numbers that are the same (5 & 5), the app will recognize this and adjust one of the numbers so that it is no longer equal to the other number. The results of rolling the dice must be the results from a random number generator, unless the results yield numbers that are identical; in that case, one of the numbers will need to be adjusted. The user must never know that the results have been changed

blic Class Form1

Private Sub btnRolldice_Click(sender As Object, e As EventArgs) Handles btnRolldice.Click
    Dim ranGem As New Random
    Dim dblnum1 As Double
    Dim dblnum2 As Double
    Dim dbltotal As Double
    dblnum1 = ranGem.Next(1, 7)
    dblnum2 = ranGem.Next(1, 7)





        Select Case dblnum1
            Case 1
                picDie1.Image = picDice1.Image
            Case 2
                picDie1.Image = picDice2.Image
            Case 3
                picDie1.Image = picDice3.Image
            Case 4
                picDie1.Image = picDice4.Image
            Case 5
                picDie1.Image = picDice5.Image
            Case 6
                picDie1.Image = picDice6.Image

        End Select
        Select Case dblnum2
            Case 1
                picDie2.Image = picDice1.Image
            Case 2
                picDie2.Image = picDice2.Image
            Case 3
                picDie2.Image = picDice3.Image
            Case 4
                picDie2.Image = picDice4.Image
            Case 5
                picDie2.Image = picDice5.Image
            Case 6
                picDie2.Image = picDice6.Image

        End Select

    dbltotal = dblnum1 + dblnum2
    lblTotal.Text = dbltotal.ToString
End Sub


Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    Me.Close()
End Sub

End Class

Recommended Answers

All 6 Replies

Do you have a question?

A few suggestions off the top.

  • You don't need a double to store a digit from 1-6. Use a Byte.
  • Use an ImageList to preload the dice images. That way you can assign an image using an index like pnlDie1.BackgroundImage = imgDice.Images(num1 - 1) instrad of a lengthy Select-Case - keeping in mind that indexes are zero-relative.
  • Create ranGem at the Class level rather than inside the Function otherwise you will get the same random number sequence every time. You can seed it when you create it by Private ranGem As New Random(Now.Second)

Also refer to this post here for more info on dice rolling.

 stackoverflow.com/questions/26522868/dice-roller-for-any-sided-dice-in-vb-net

From what i understood, when u generate a number you always want two numbers to be different. if i understood right this will work

Dim ranGem As New Random
Dim dblnum1 As Double
Dim dblnum2 As Double
dblnum1 = ranGem.Next(1, 7)
Do
  dblnum2 = ranGem.Next(1, 7)
Loop Until (dblnum2.Equals(dblnum1) = False)

Perhaps you wanted something like this?
i suggest u keep the 2 numbers as integers (or better yet, byte as Reverend Jim said).

I want to prevent the roll of doubles no (4,4) if this happends its suppose to create a new out put and that are diffent

Thanks necrovore i believe it worked

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.