关于随机数的问题
有没有什么方法让产生的随机数按某一统计规律出现?比如:产生1~9的整数,1出现的机率是5%,2出现的机率是10%……
????
Option Explicit Dim 概率(99) As Long Dim 结果(9) As Long Dim stopyn As Boolean Private Sub Command1_Click() '开始计算 stopyn = False Dim i As Long Dim j As Long Do While Not stopyn i = Int(Rnd() * 100) 结果(概率(i)) = 结果(概率(i)) + 1 DoEvents Loop End Sub Private Sub Command2_Click() '停止计算 stopyn = True End Sub Private Sub Command3_Click() '显示结果 Call Timer1_Timer End Sub Private Sub Form_Load() '初始化概率 Dim i As Long i = 产生概率(0, 0, 5) i = 产生概率(1, i, 5) i = 产生概率(2, i, 9) i = 产生概率(3, i, 11) i = 产生概率(4, i, 5) i = 产生概率(5, i, 5) i = 产生概率(6, i, 35) i = 产生概率(7, i, 5) i = 产生概率(8, i, 15) i = 产生概率(9, i, 5) End Sub Private Function 产生概率(数值 As Long, 起始位置 As Long, 概率值 As Long) As Long '产生概率 Dim i As Long Dim j As Long i = 起始位置 For j = 1 To 概率值 概率(i) = 数值 i = i + 1 Next j 产生概率 = i End Function Private Sub Timer1_Timer() '显示结果 Dim i As Long Dim j As Long For i = 0 To 9 j = j + 结果(i) Next i With Me .Cls For i = 0 To 9 Me.Print i, 结果(i), "占总数:", If j > 0 Then Me.Print (结果(i) / j) * 100, End If Me.Print Next i End With DoEvents End Sub