dimanche 30 août 2020

Visual Basic: I'm trying to roll two dice [duplicate]

In Visual Basic, I'm trying to roll two dice. I'm always getting die1 and die2 being the same random Integer from 1 to 6. Why aren't die1 and die2 each random and showing as different random values??? In the RollD6() function, n is of local scope within RollD6(), right?

Public Class frmCrapsWin
    Dim pot As Decimal = 0D
    Dim point, result As Integer
    Dim wager As Decimal = 0D
    Dim points(99) As Integer
    Dim wagerCoefficient(99) As Decimal

    Function RollD6() As Integer
        Dim randomNum As New Random
        Dim n As Integer
        n = randomNum.Next(1, 7)  ' random number (1,6)
        Return n
    End Function

    Private Sub btnRoll_Click(sender As Object, e As EventArgs) Handles btnRoll.Click
        Dim die1 As Integer
        Dim die2 As Integer
        die1 = RollD6()
        die2 = RollD6()
        lstOutput.Items.Add("die 1: " & die1 & "    die 2: " & die2 & "     Result: " & (die1 + die2))
        lstOutput.Items.Add("die 1: " & die1)
        lstOutput.Items.Add("die 2: " & die2)

    End Sub
End Class




Aucun commentaire:

Enregistrer un commentaire