python模拟十万次抽牌
import random
i=0
j=0
k=100000
b=[0]*10
for indes in range(k):
a=random.sample(range(0,52),10)
while i<10:
b[i]=a[i]//13
i=i+1
if 0 in b and 1 in b and 2 in b and 3 in b:
j=j+1
i=0
print(j/k)
结果约为0.84
MATLAB用两种方法计算
format long
%待求概率
1-(4*nchoosek(13,10)+(nchoosek(26,10)-2*nchoosek(13,10))*6+(nchoosek(39,10)-(nchoosek(26,10)-2*nchoosek(13,10))*3-3*nchoosek(13,10))*4)/nchoosek(52,10)
%有且只有两种花色的组合数量/方法1
(nchoosek(26,10)-2*nchoosek(13,10))*6
%有且只有两种花色的组合数量/方法2
((13*nchoosek(13,9)+nchoosek(13,2)*nchoosek(13,8)+nchoosek(13,3)*nchoosek(13,7)+nchoosek(13,4)*nchoosek(13,6))*2+nchoosek(13,5)*nchoosek(13,5))*6
%有且只有三种花色的组合数量/方法1
(nchoosek(39,10)-(nchoosek(26,10)-2*nchoosek(13,10))*3-3*nchoosek(13,10))*4
%有且只有三种花色的组合数量/方法2
(13*(nchoosek(13,1)*nchoosek(13,8)+nchoosek(13,2)*nchoosek(13,7)*2+nchoosek(13,3)*ncho