Simulation

A seeded random walk and a tiny kiosk queue.

A simulation is a model that steps through time. Seed the random number generator so the run is repeatable. Count outcomes; do not plot (no matplotlib in this editor).

Goal

Walk a seeded random path on a city ring, then simulate a tiny kiosk queue.

Random walk on cities

import random

random.seed(1)
cities = ["Nairobi", "Nakuru", "Eldoret"]
pos = 0
path = [cities[pos]]
for _ in range(6):
    step = random.choice([-1, 1])
    pos = (pos + step) % len(cities)
    path.append(cities[pos])
print(path)
print("ended", path[-1])

Same seed → same path. Change the seed and the path changes.

Kiosk queue

import random
from collections import deque

random.seed(2)
line = deque()
served = 0
for minute in range(8):
    if random.random() < 0.6:
        line.append("c" + str(minute))
    if line and random.random() < 0.5:
        line.popleft()
        served += 1
    print("t", minute, "waiting", len(line), "served", served)
print("final waiting", len(line))

Each minute, someone may join and someone may be served. That is a discrete-time simulation.

Tip

random.seed is part of the experiment, not cheating. Science wants a run another person can repeat.