【发布时间】:2014-04-28 10:32:58
【问题描述】:
大家好,下面我将粘贴我的代码以找出滚动结果的百分比机会(请参阅我的最后一个结果以获取提醒)
我要做的几乎是掷 3 个骰子,将总数存储在 18 个 texbox 中(每个总数 3,18 个),然后根据滚动次数计算出总数的百分比机会
(一个公平的警告,我的数学有点不对劲,但是与代码混在一起会使情况变得更糟,而且我只是一年级程序员,需要任何帮助:()
Imports System.Math
Public Class Form1
Dim Numthrow As Integer
Dim diceValue(18) As Integer
Dim randomGen = New Random()
Dim total As Integer
Dim percenttotal(18) As Integer
Dim cent As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Numthrow = TextBox1.Text
For index = 1 To Numthrow
Dim diceResult1 = randomGen.Next(1, 7)
Dim diceResult2 = randomGen.Next(1, 7)
Dim diceResult3 = randomGen.Next(1, 7)
total = diceResult1 + diceResult2 + diceResult3
diceValue(total) += 1
cent = Numthrow * 100 / total
percenttotal(cent) += 1
Next
Label21.Text = percenttotal(3)
Label22.Text = percenttotal(4)
Label23.Text = percenttotal(5)
Label24.Text = percenttotal(6)
Label25.Text = percenttotal(7)
Label26.Text = percenttotal(8)
Label27.Text = percenttotal(9)
Label28.Text = percenttotal(10)
Label29.Text = percenttotal(11)
Label30.Text = percenttotal(12)
Label31.Text = percenttotal(13)
Label32.Text = percenttotal(14)
Label33.Text = percenttotal(15)
Label34.Text = percenttotal(16)
Label35.Text = percenttotal(17)
Label36.Text = percenttotal(18)
TextBox2.Text = diceValue(3).ToString()
TextBox3.Text = diceValue(4).ToString()
TextBox4.Text = diceValue(5).ToString()
TextBox5.Text = diceValue(6).ToString()
TextBox6.Text = diceValue(7).ToString()
TextBox7.Text = diceValue(8).ToString()
TextBox8.Text = diceValue(9).ToString()
TextBox9.Text = diceValue(10).ToString()
TextBox10.Text = diceValue(11).ToString()
TextBox11.Text = diceValue(12).ToString()
TextBox12.Text = diceValue(13).ToString()
TextBox13.Text = diceValue(14).ToString()
TextBox14.Text = diceValue(15).ToString()
TextBox15.Text = diceValue(16).ToString()
TextBox16.Text = diceValue(17).ToString()
TextBox17.Text = diceValue(18).ToString()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
diceValue(18) = 0
percenttotal(18) = 0
End Sub
End Class
【问题讨论】:
-
是的,所以总结果是 216,我最近将其更改为
-
cent = Numthrow / total * 100 这是 numthrow 可以是 100 / 3 个骰子的总数,可以在 3,18 之间然后乘以 100 得到概率
标签: .net vb.net random probability dice