编程模拟概率的问题
来源:百度知道 编辑:UC知道 时间:2024/06/30 04:11:23
谢谢,这是手动抽,如果要自动抽取2000次怎样编呢
Option Explicit
Dim ArrData(1 To 3) As Integer
Dim ArrCount(1 To 13) As Integer
Dim i As Integer
Dim j As Integer
Private Sub Command1_Click()
For i = 1 To 3
RE:
Randomize
ArrData(i) = 1 + Int(Rnd * 12) '在1到13的范围生成随机数字
For j = i To 2 Step -1
If ArrData(j) = ArrData(j - 1) Then '如果与前面的数字相同则重新生成
GoTo RE
End If
Next j
ArrCount(ArrData(i)) = ArrCount(ArrData(i)) + 1 '统计出现次数
Print ArrData(i);
Next i
Print
End Sub
Private Sub Command2_Click()
Dim TempCount As Integer
Dim TempIndex As Integer
Dim Str As String
For i = 1 To 13 '统计出现最多的数字
If ArrCount(i) > TempCount Then
TempCount = ArrCount(i)
TempIndex = i
End If
Next i
Str = "出现最多的数字是:"
For i = 1 To 13 '当几个数字出现次数相同且为最多时
If ArrCount(i) = TempCount Then
Str = Str & i & ","<