使用VBA解题
修改一下,把模拟1W次改成了10W次,这个问题我有理论解.附图给你参考一下,
Sub 运行()
Dim a, b, c, m, n, i, j, k, x, y, sum
Dim arr(8) '发生次数
Dim p(8) '权重
For k = 1 To 100000
p(1) = 100 '赋值
For i = 2 To 8
p(i) = p(i - 1) + 100
Next
For j = 1 To 4 '抽取4次
'随机
sum = 0
For i = 1 To 8
sum = sum + p(i)
Next
x = WorksheetFunction.RandBetween(1, sum)
'动作
Select Case x
Case Is <= p(1)
arr(1) = arr(1) + 1
p(1) = 0
Case Is <= p(1) + p(2)
arr(2) = arr(2) + 1
p(2) = 0
Case Is <= p(1) + p(2) + p(3)
arr(3) = arr(3) + 1
p(3) = 0
Case Is <= p(1) + p(2) + p(3) + p(4)
arr(4) = arr(4) + 1
p(4) = 0
Case Is <= p(1) + p(2) + p(3) + p(4) + p(5)
arr(5) = arr(5) + 1
p(5) = 0
Case Is <= p(1) + p(2) + p(3) + p(4) + p(5) + p(6)
arr(6) = arr(6) + 1
p(6) = 0
Case Is <= p(1) + p(2) + p(3) + p(4) + p(5) + p(6) + p(7)
arr(7) = arr(7) + 1
p(7) = 0
Case Is <= p(1) + p(2) + p(3) + p(4) + p(5) + p(6) + p(7) + p(8)
arr(8) = arr(8) + 1
p(8) = 0
End Select
Next
Next
For i = 1 To 8
Sheet1.Cells(i, 1).Value = arr(i)
Next
End Sub