Private p1 Private s1, s2, s3, s4, s5, s6, s7, s8, s9, s10 Private S Sub tt1() Call intial1 S = 10000 For i = 1 To S Call RR1 Call SS1 ' Debug.Print p1 Next Call SS2 End Sub Function intial1() s1 = 0 s2 = 0 s3 = 0 s4 = 0 s5 = 0 s6 = 0 s7 = 0 s8 = 0 s9 = 0 s10 = 0 End Function Function SS2() Debug.Print "随到1的平均次数是= " & s1 / S & " s1=" & s1 Debug.Print "随到2的平均次数是= " & s2 / S & " s2=" & s2 Debug.Print "随到3的平均次数是= " & s3 / S & " s3=" & s3 Debug.Print "随到4的平均次数是= " & s4 / S & " s4=" & s4 Debug.Print "随到5的平均次数是= " & s5 / S & " s5=" & s5 Debug.Print "随到6的平均次数是= " & s6 / S & " s6=" & s6 Debug.Print "随到7的平均次数是= " & s7 / S & " s7=" & s7 Debug.Print "随到8的平均次数是= " & s8 / S & " s8=" & s8 Debug.Print "随到9的平均次数是= " & s9 / S & " s9=" & s9 Debug.Print "随到10的平均次数是= " & s10 / S & " s10=" & s10 End Function Function RR1() Randomize p1 = Int(1 + (10) * Rnd()) 'Rnd()分别修改为 rnd(-1) rnd(0) rnd(1) rnd(999) 看效果 'Debug.Print p1 End Function
Function SS1() Select Case p1 Case Is = 1 s1 = s1 + 1 Case Is = 2 s2 = s2 + 1 Case Is = 3 s3 = s3 + 1 Case Is = 4 s4 = s4 + 1 Case Is = 5 s5 = s5 + 1 Case Is = 6 s6 = s6 + 1 Case Is = 7 s7 = s7 + 1 Case Is = 8 s8 = s8 + 1 Case Is = 9 s9 = s9 + 1 Case Is = 10 s10 = s10 + 1 End Select End Function