I have a question related to dice. Suppose there are 6 dice, and each die is rolled to receive a random value. Let the set of values obtained be represented as $\{a_1, a_2, ..., a_6\}$.
The problem I'm trying to solve is: What is the probability that, among the 6 random numbers obtained from the dice, there exists at least one subset of three numbers whose sum equals 6?
Here’s how I approached the problem:
The probability that the sum of three dice equals 6 is $10/216$. The number of ways to choose 3 numbers from 6 is $6 \choose 3$. Therefore, the probability can be computed as $1 - (1 - 10/216)^{20}$. Thus, the probability that at least one subset of three numbers sums to 6 is $61.25$%. To verify this, I wrote a program to simulate this process, but the actual value I obtained was quite different from my theoretical result.
Both checking all possible cases and running a simulation 100,000 times gave me a result of approximately $41$%.
Why is there such a discrepancy between the theoretical calculation and the actual result? How can I reconcile this difference?
Here is the code I used:
import math
import random
import os
import itertools
n = 6
m = 3
t = 6
print(f'Probability that the sum of {m} dice out of {n} dice is {t}')
dice = [1, 2, 3, 4, 5, 6]
hap = 0
total = 0
ALL_Events = [[]]
for i in range(m):
ALL_Events = [E + [e] for e in dice for E in ALL_Events]
for E in ALL_Events:
if t == sum(E):
hap += 1
total += 1
one_set_prob = hap / total
print(f'Probability that the sum of {m} dice is {t} : {hap}/{total} = {one_set_prob * 100:.2f}%')
com = math.comb(n, m)
calc_prob = 1 - ((1 - one_set_prob) ** com)
print(f'Probability that the sum of {m} dice out of {n} is {t} (calculated): {calc_prob * 100:.2f}% (= 1 - {1 - one_set_prob:.4f} ^ {com})')
random.seed(os.urandom(16))
hap = 0
total = 0
for i in range(100000):
E = [random.choice(dice) for _ in range(n)]
for e in itertools.combinations(E, m):
if t == sum(e):
hap += 1
break
total += 1
test_prob = hap / total
print(f'Probability that the sum of {m} dice out of {n} is {t} (test): {test_prob * 100:.2f}%')
hap = 0
total = 0
ALL_Events = [[]]
for i in range(n):
ALL_Events = [E + [e] for e in dice for E in ALL_Events]
for E in ALL_Events:
for e in itertools.combinations(E, m):
if t == sum(e):
hap += 1
break
total += 1
real_prob = hap / total
print(f'Probability that the sum of {m} dice out of {n} is {t} (actual value): {real_prob * 100:.2f}%')
```