Simulation generates artificial outcomes by repeatedly applying specified rules or probability models. For a device expected to succeed 90% of the time, it can test whether observing 7 successes in 10 trials is unusual or merely random variation. section 3.7
from random import random
p = 0.9 #1
outcomes = {key: 0 for key in range(11)} #2
for i in range(10000): #3
successes = 0
for j in range(10): #4
if random() < p: #5
successes += 1
outcomes[successes] +=1
for k,v in outcomes.items(): #6
print(f"Experiments with {k} successes: {v}") #6
Run 10,000 experiments, each containing 10 simulated trials. Each trial draws a random number and counts success when it falls below p = 0.9; the resulting counts show the distribution of outcomes. section 3.7
Testing a 7-out-of-10 result
The simulation finds that 7 successes in 10 trials can occur under a 90% success probability, but represents only about 6.1% of simulated experiments. Repeating the run may produce slightly different proportions because the procedure is random. A bar chart makes the outcome distribution visible, while a binomial calculation gives a closely related probability of about 0.0574. section 3.7





