怎样用VB写一个这样的程序
提示: 作者被禁止或删除 内容自动屏蔽
Option Explicit '对应0-27 出现的概率,以总数计 Const klb = "1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 13 12 11 10 9 8 7 6 5 4 3 2 1" Dim kl(27) As Double Private Type 数据结构 算式 As String 结果 As Long End Type Dim jg(999) As 数据结构 Dim 分布(28) As Long Dim 统计(27) As Long Private Sub Command1_Click() '显示20组 Cls Dim i As Long, j As Double Dim n As Long, m As Long Dim o As Long For o = 1 To 20 Do j = Rnd() '产生概率 For i = 0 To 27 '搜索概率 If j < kl(i) Then Exit For End If Next i Loop While i < 0 统计(i) = 统计(i) + 1 n = 分布(i + 1) - 分布(i) If n = 1 Then m = 分布(i) Else m = 分布(i) + Int(Rnd() * n) End If 'Print j, i, n, m, 'Debug Print jg(m).算式 Next o End Sub Private Sub Command2_Click() '显示统计结果 Dim i As Long, j As Long Cls For i = 0 To 27 j = 统计(i) + j Next i Print "序号", "统计的数量", "占百分比", "设置百分比", "与设置的相差百分比" For i = 0 To 27 Print i, 统计(i), Round(统计(i) / j * 100, 2) & "%", '基础统计数据 If i > 0 Then Print Round((kl(i) - kl(i - 1)) * 100, 2) & "%", '原始比例 Print Round(统计(i) / j * 100, 2) - Round((kl(i) - kl(i - 1)) * 100, 2) & "%" '与原始比例之差 Else Print Round((kl(i)) * 100, 2) & "%", '原始比例 Print Round(统计(i) / j * 100, 2) - Round(kl(i) * 100, 2) & "%" '与原始比例之差 End If Next i End Sub Private Sub Command3_Click() Dim o As Long Dim i As Long, j As Double Dim n As Long, m As Long For o = 1 To 10000 '产生10000次,不显示 Do j = Rnd() '产生概率 For i = 0 To 27 '搜索概率 If j < kl(i) Then Exit For End If Next i Loop While i < 0 统计(i) = 统计(i) + 1 n = 分布(i + 1) - 分布(i) If n = 1 Then m = 分布(i) Else m = 分布(i) + Int(Rnd() * n) End If Next o '产生完成后,显示结果 Call Command2_Click End Sub Private Sub Form_Load() '初始化 Dim i As Long, j As Long, k As Long Dim n As String, m As Long Dim fj() As String '计算各个结果的概率段 fj = Split(klb, " ") For i = 0 To 27 j = Val(fj(i)) + j Next i For i = 0 To 27 If i > 0 Then kl(i) = Val(fj(i)) / j + kl(i - 1) Else kl(i) = Val(fj(i)) / j End If Next i '产生算式及结果 For i = 0 To 9 For j = 0 To 9 For k = 0 To 9 jg(i * 100 + j * 10 + k).算式 = i & " + " & j & " + " & k & " = " & i + j + k jg(i * 100 + j * 10 + k).结果 = i + j + k Next k Next j Next i '对结构进行排序 For i = 0 To 999 k = i For j = i To 999 If jg(k).结果 > jg(j).结果 Then k = j End If Next j m = jg(i).结果 n = jg(i).算式 jg(i).结果 = jg(k).结果 jg(i).算式 = jg(k).算式 jg(k).结果 = m jg(k).算式 = n Next i '统计各个结果的开始序号 j = 0 For i = 0 To 999 If jg(i).结果 <> j Then j = j + 1 分布(j) = i End If Next i '最后一个数据为1000,确保不出错 分布(28) = 1000 End Sub