求excel公式高手解决难题!!

2024-12-12 22:50:19
推荐回答(2个)
回答1:

找一个空白工作表,使用下面代码就可以模拟抽牌的过程,不论怎么抽,结果都是180
Sub 牌()
'初始化
t = "1234567890000"
For i = 1 To 4: tt = tt & t: Next
Randomize
'开始抽牌
Dim a As Integer
Dim b As Integer
For i = 1 To 26
s = Len(tt)
10:00
a = Int(Rnd() * s) + 1
b = Int(Rnd() * s) + 1
If a = b Then GoTo 10
If a > b Then c = a: a = b: b = c
aa = Mid(tt, a, 1): bb = Mid(tt, b, 1)
Cells(i, 1) = Val(aa) + Val(bb)
tt = Left(tt, a - 1) & Mid(tt, a + 1, b - a - 1) & Right(tt, s - b)
Cells(i, 2) = tt
Next
MsgBox "和是" & WorksheetFunction.Sum(Range(Cells(1, 1), Cells(26, 1)))
End Sub

回答2:

我用笨办法求出的结果是这样的:
和 百分比
0 9.049773756
1 4.826546003
2 5.279034691
3 6.033182504
4 6.485671192
5 7.239819005
6 7.692307692
7 8.446455505
8 8.898944193
9 9.653092006
10 5.279034691
11 4.826546003
12 4.07239819
13 3.619909502
14 2.865761689
15 2.413273002
16 1.659125189
17 1.206636501
18 0.452488688