Monte Carlo simulation models an uncertain real-world process by repeatedly generating random values from probability distributions. Comparing runs reveals possible outcomes when collecting real-world data is difficult. section 3.11 section 3.12
Planning a coffee-shop hire
A coffee-shop owner wants to estimate the extra espresso shots an inexperienced barista might pull during a three-hour morning. A Poisson model can simulate shots per minute; an exponential model can generate the elapsed time before each shot. Repeated runs produce different totals, typically around 40–70 shots, while the exponential version also supplies a delivery timeline. section 3.11
A practical simulation workflow is:
- Choose a probability distribution that matches the question: event counts over an interval or time between events. section 3.11 section 3.12
- Generate random outcomes, accumulate them across the time window, and compare results across runs. section 3.11
from numpy.random import exponential as expon
mu = .3 #1
time_elapsed = 0.0 #2
shots_pulled = 0 #3
while True: #4
time_elapsed_to_shot = expon(scale=1/mu, size=1)[0] #5
time_elapsed += time_elapsed_to_shot #6
if time_elapsed > 180: #7
break #8
shots_pulled += 1 #9
print(f"{time_elapsed:.2f} minutes: {shots_pulled} shots pulled") #10
print(f"Total shots pulled in 3 hours: {shots_pulled}") #11
The event-timeline implementation generates exponential waiting times, stops after 180 minutes, and counts each completed shot. section 3.11







