让
- x = 100X是您范围的上限,在您的情况下,。x = 100
- n = 25ñ是总抽奖次数,在您的情况下为。n = 25
对于任何数字,数字的序列数为,序列中的每个数字。在这些序列中,不包含 s 的数为,而包含一个的数为。因此,具有两个或多个 s 的序列数为
包含最高的个数
为序列的总数至少两个是
Ñ ≤ ÿ ÿ Ñ ý (Ý - 1 )ñ Ý Ñ (Ý - 1 )ñ - 1个 Ÿ Ÿ ñ - (Ý - 1 )ñ - ñ (Ý - 1 )ñ - 1 ñ ÿ ÿ X Σ y = 1(y n − (y − 1ÿ≤ Xñ≤ ÿÿñÿ(y− 1 )ñÿÑ (ÿ− 1 )n − 1ÿ
ÿñ− (y− 1 )ñ− n (y− 1 )n − 1
ñÿÿ∑ÿ= 1X(yñ− (y− 1 )ñ− n (y− 1 )n − 1)= ∑ÿ= 1Xÿñ− ∑ÿ= 1X(y− 1 )ñ− ∑ÿ= 1XÑ (ÿ− 1 )n − 1= xñ− n ∑ÿ= 1X(y− 1 )n − 1= xñ− n ∑ÿ= 1x − 1ÿn − 1
序列的总数仅为。所有序列的可能性均等,因此概率为
Xñ
Xñ− n ∑ÿ= x − 1ÿ= 1ÿn − 1Xñ
在我得出的概率为0.120004212454。x = 100 ,n = 25
我使用以下Python程序进行了测试,该程序对手动匹配的序列进行计数(对于低),并使用上述公式进行模拟和计算。X ,ñ
import itertools
import numpy.random as np
def countinlist(x, n):
count = 0
total = 0
for perm in itertools.product(range(1, x+1), repeat=n):
total += 1
if perm.count(max(perm)) > 1:
count += 1
print "Counting: x", x, "n", n, "total", total, "count", count
def simulate(x,n,N):
count = 0
for i in range(N):
perm = np.randint(x, size=n)
m = max(perm)
if sum(perm==m) > 1:
count += 1
print "Simulation: x", x, "n", n, "total", N, "count", count, "prob", count/float(N)
x=100
n=25
N = 1000000 # number of trials in simulation
#countinlist(x,n) # only call this for reasonably small x and n!!!!
simulate(x,n,N)
formula = x**n - n*sum([i**(n-1) for i in range(x)])
print "Formula count", formula, "out of", x**n, "probability", float(formula) / x**n
该程序输出
Simulation: x 100 n 25 total 1000000 count 120071 prob 0.120071
Formula count 12000421245360277498241319178764675560017783666750 out of 100000000000000000000000000000000000000000000000000 probability 0.120004212454