CSC 406
Computer Modelling and Simulation
Complete Topic Guide — Explanations & Worked Examples
Covers: Basics & Definitions, the Simulation Process, Distribution Theory, Model vs. Simulation, Queues, Stochastic
Processes, and Random Numbers.
PART 1: Basics of Modelling and Simulation
1.1 Definitions
• Model — a simplified stand-in for something real: a plan, description, or set of equations that captures the
essential behaviour of a system without all its real-world detail. A model airplane doesn't fly people, but lets
engineers study aerodynamics cheaply.
• Modelling — the process of building that stand-in (deciding what to include, what to leave out, and how the
pieces relate).
• Simulation — running the model over time or space so you can observe how it behaves, like flipping through
a flipbook so still drawings become motion.
• Modelling and Simulation (M&S) — the overall discipline of using models to understand how the parts of a
system interact, and how the whole system behaves, in ways too expensive, slow, or dangerous to test
directly.
1.2 Types of Models
Type What it is Example
Physical / Iconic A scaled physical replica Model railway, model car
Mathematical Equations describing relationships f = ma; Interest = P×R×T/100
Pressure gauge dial for tyre
Analogue One physical quantity stands in for another
pressure
Represented using streams of random
Simulation A queue simulation
numbers
Early satellite-communication
Heuristic Built on intuitive/rule-of-thumb logic
concepts
Fixed, known constants; same input gives Economic Order Quantity
Deterministic
same output formula
Contains one or more uncertain (random)
Stochastic Customer arrival patterns
variables
1.3 Why We Use Models (Advantages / Uses)
• Safer — no risk to people or equipment (flight simulators vs. real planes).
• Cheaper — no need to build/break the real system to learn from it.
• Easier to control — you can freeze time, rerun scenarios, and isolate variables you can't isolate in the real
world.
Especially valuable when: outcomes are uncertain, the system has complex multi-part interactions, or
consequences are delayed, expensive, or impossible to observe directly.
1.4 The Modelling Procedure (Steps)
1. Examine the real-world situation.
2. Extract the essential features (drop anything that doesn't meaningfully affect the outcome).
3. Construct the model using just those essential features.
4. Solve / experiment with the model.
5. Draw conclusions.
6. If refinement is needed, adjust parameters and repeat from step 4.
7. Implement.
Worked example — applying the procedure: A supermarket wants to know if adding a second checkout
counter is worth it. Real situation: one till, growing complaints about wait time. Essential features: arrival rate,
service time per customer, number of tills. Model: a queuing system (see Part 5) with λ = arrival rate, µ =
service rate per till. Solve: run the queue formulas with 1 till, then 2, and compare wait time (Wq). Conclusion:
if Wq drops enough to justify the cost, implement the second till.
PART 2: The Simulation Process
2.1 Steps in Constructing a Simulation Model
1. Formulate the model (as above).
2. Design the experiment — decide parameters, data structures, and relationships before running anything.
3. Develop the computer program — code it in a general-purpose language (BASIC, C) or a dedicated simulation
language (GPSS, SIMULA, SIMNET II).
2.2 Core Simulation Vocabulary
Illustrated using a single-pump gas station:
Term Meaning Gas-station example
The variable(s) describing the system right Number of cars waiting +
State
now being served
Car arrives, service starts,
Event Something that changes the state
service ends
Entity The object flowing through the system The cars
Anywhere entities wait for something to
Queue The line of cars at the pump
happen
Creating Spawning a new entity into the system A new car arrives
Booking the moment this
Scheduling Assigning a future event to an entity
car's service ends
Random variable An uncertain quantity Time between arrivals
An artificially generated instance of a The specific arrival-gap value
Random variate
random variable drawn
The mathematical law governing a Exponential distribution for
Distribution
random variable arrival gaps
2.3 Types of Simulation
• Continuous — time and state change smoothly; modelled with differential equations. Example: water level
in a reservoir.
• Discrete-event — the state only changes at specific instants (events); nothing happens between events.
Example: customers arriving at a bank.
• Stochastic vs. Deterministic — whether randomness is involved.
• Steady-state vs. Dynamic — whether you're looking for a long-run equilibrium or tracking change over time.
Worked example — classifying a system: A hospital emergency room where patients arrive unpredictably and
are treated one at a time. Time representation → discrete-event (state only changes at arrival/departure
instants). Randomness → stochastic (arrivals and treatment times vary). This combination is exactly what
queuing theory (Part 5) is built to analyse.
PART 3: Some Distribution Theory
Distribution theory matters because a simulation is only as realistic as the randomness feeding it — you don't
just need "random numbers," you need numbers shaped like the real-world process you're modelling.
3.1 Descriptive vs. Inferential Statistics
• Descriptive statistics — summarising data you already have: central tendency (mean, median, mode) and
dispersion (variance, standard deviation).
• Inferential statistics — using a sample to make claims about a bigger population (you can't observe every
possible customer, so you estimate patterns from a sample).
3.2 Common Probability Distributions
Distribution Models...
Continuous quantities clustering around a mean (errors,
Normal (Gaussian)
measurements)
Uniform Equally likely outcomes (a fair die)
Bernoulli / Binomial Yes/no trials, or count of successes across trials
Count of independent events in a fixed time window (arrivals per
Poisson
hour)
Exponential Time between independent events (time between arrivals)
Erlang Sum of several exponential stages (multi-stage service time)
Poisson and Exponential are the two the queuing sections lean on most heavily, because arrivals are almost
always modelled as Poisson, with exponential inter-arrival gaps.
3.3 Worked Example — Poisson Distribution
Jobs arrive at a machine following a Poisson process at λ = 2 per hour. The machine breaks down for t = 1 hour.
Find the probability that 0, 2, or 5-or-more jobs arrive during the downtime.
Mean arrivals during downtime: λt = 2 × 1 = 2
Formula: P(N = n) = (λt)ⁿ e^(−λt) / n! , and e^(−2) ≈ 0.1353
• P(0) = 0.1353
• P(2) = (2² × 0.1353) / 2! = 0.5412 / 2 = 0.2707
For P(≥5), use the complement:
• P(1) = 2 × 0.1353 = 0.2707
• P(3) = (8 × 0.1353)/6 = 0.1804
• P(4) = (16 × 0.1353)/24 = 0.0902
• Sum P(0..4) = 0.1353+0.2707+0.2707+0.1804+0.0902 = 0.9473
P(≥5) = 1 − 0.9473 = 0.0527 (about 5.3%)
PART 4: Model and Simulation — the Relationship
These two terms are often blurred together, so it's worth separating them cleanly:
• A model is the static blueprint — the equations, rules, or representation of the system.
• A simulation is the act of exercising that blueprint across time to observe behaviour you couldn't otherwise
see directly.
• The relationship between them is iterative: build model → simulate → learn from results → revise the model
→ simulate again — repeating until the model's behaviour is close enough to reality to trust its conclusions.
Analogy: the model is the recipe; the simulation is actually cooking the dish, tasting it, and adjusting the recipe
until it's right.
PART 5: Queues
5.1 Basic Components of a Queuing System
A queue is fully defined by:
• Arrival process — how customers enter (rate λ, and its distribution)
• Service process — how they're served (rate µ, and its distribution)
• Number of servers
• System capacity — is there a maximum queue length?
• Size of the source population — finite or infinite pool of potential customers?
5.2 Kendall(-Lee) Notation
Shorthand for describing a queue: A / B / C / N / K
• A = arrival-time distribution
• B = service-time distribution
• C = number of parallel servers
• N = system capacity (max customers allowed)
• K = size of the population source
Distribution codes: M = exponential (Markovian), D = deterministic/constant, E = Erlang, G = general.
Example: M/M/1 = exponential arrivals, exponential service, 1 server, unlimited capacity, infinite population (N
and K dropped when infinite).
5.3 Queuing Rules (Queue Discipline)
• FIFO/FCFS — first in, first out (supermarket line)
• LIFO — last in, first out (a stack of plates)
• SIRO — service in random order
• PR — priority (VIPs served first)
• Processor sharing — everyone served simultaneously but slower (shared bandwidth)
5.4 Little's Law
L = λW
• L = average number of customers in the system
• λ = arrival rate
• W = average time a customer spends in the system
Intuition: if customers arrive at rate λ and each stays W time units, then on average L of them are in the
system at once — like a bathtub: the water sitting in it equals the inflow rate times how long each drop stays
before draining.
5.5 Queuing Networks
Multiple queues linked together, where customers move from one server to the next (e.g., a factory production
line).
• Open networks — customers can enter/leave the overall system.
• Closed networks — a fixed number of customers circulate permanently within the system.
5.6 Special / Types of Queues (built on Kendall notation)
• M/M/1 — single server, unlimited queue, infinite population (the simplest case).
• M/M/1/GD/c/∞ — single server, capacity capped at c customers (arrivals beyond that are turned away).
• M/M/s/GD/∞/∞ — multiple (s) parallel servers sharing one queue, unlimited capacity.
• M/G/s/GD/s — multiple servers, general service time, no waiting room (arrivals blocked if all servers busy —
"cleared" systems).
5.7 Worked Example — Full M/M/1 Queue
Scenario: A single bank teller. Customers arrive at λ = 12/hour (Poisson), teller serves at µ = 15/hour
(exponential).
Classify it first: exponential arrivals, exponential service, 1 server, no limits → M/M/1.
Step Formula Calculation Result
0.8 (teller busy 80% of the
1. Utilization ρ = λ/µ 12/15
time)
2. Avg. number in
L = ρ/(1−ρ) 0.8/0.2 4 customers
system
3. Avg. number
Lq = ρ²/(1−ρ) 0.64/0.2 3.2 customers
waiting
4. Avg. time in system W = L/λ 4/12 0.333 hr = 20 min
5. Avg. time waiting Wq = Lq/λ 3.2/12 0.267 hr ≈ 16 min
Check using W = Wq + 1/µ: 16 min + 1/15 hr (4 min) = 20 min ✓ — matches Step 4.
5.8 Worked Example — Queuing Networks (Pooled vs. Separate Servers)
System A — one pooled queue, 8 servers sharing one line:
Total λ = 8 lines × 2 packets/s = 16 packets/s. Total µ = 64 kbit/s ÷ 2000 bits/packet = 32 packets/s.
Response time = 1/(µ−λ) = 1/(32−16) = 0.0625 s
System B — 8 separate queues, one server each:
Each line: λ = 2 packets/s, µ = 8000 bits/s ÷ 2000 bits/packet = 4 packets/s.
Response time = 1/(µ−λ) = 1/(4−2) = 0.5 s
Conclusion: same total capacity either way, but the pooled system (A) is 8× faster — this is why banks put
customers in one line feeding multiple tellers, rather than a separate line per teller.
PART 6: Stochastic Processes
A stochastic process is a family of random variables indexed by time: {X(t), t ∈ T}. Instead of tracking one
number, you track how a random quantity evolves — like a stock price moving over time, not just its value at
one instant.
6.1 Discrete-State vs. Continuous-State Processes
Continuous state Discrete state
Continuous time Water level behind a dam Number of customers in a bank
Discrete time Weekday's temperature range Sales total at end of day
• Discrete-state — the process can only take countable values (0, 1, 2, 3 customers…).
• Continuous-state — the process can take any value in a range (water level, temperature).
Time itself can also be tracked either continuously or only at discrete checkpoints — the two classifications
(state and time) are independent of each other.
6.2 Markov Processes
The defining property is memorylessness: given the current state, the future doesn't depend on how you got
there — only on where you are right now. This is why queuing models use Markov chains: you only need to
know how many people are in line at this moment to predict what happens next.
Worked example: Two states, Sunny (S) and Rainy (R), with transition probabilities: P(S→S)=0.7, P(S→R)=0.3,
P(R→S)=0.4, P(R→R)=0.6. Question: If today is sunny, what's the probability it's rainy in 2 days? Two paths
lead to Rain in 2 steps: S→S→R: 0.7×0.3 = 0.21; S→R→R: 0.3×0.6 = 0.18. P(Rain in 2 days | Sunny today) = 0.21
+ 0.18 = 0.39. Notice we never needed yesterday's weather — only today's state. That's the Markov property in
action.
6.3 Birth-Death Processes
A birth-death process is a Markov process where the state can only move up by one (a birth = an arrival) or
down by one (a death = a service completion) — never jump by more than one at a time. Each state j has its own
birth rate λⱼ and death rate µⱼ. This is exactly the structure underlying queuing theory's steady-state equations.
Worked example (reusing the bank from 5.7): λ = 12/hr, µ = 15/hr at every state, ρ = 0.8.
Steady-state formula: Πⱼ = (1−ρ)ρʲ
• Π₀ (teller idle) = 1 − 0.8 = 0.20
• Π₁ (1 customer) = 0.2 × 0.8 = 0.16
• Π₂ (2 customers) = 0.2 × 0.8² = 0.128
• Π₃ (3 customers) = 0.2 × 0.8³ = 0.1024
These probabilities keep shrinking as j grows — which only happens because ρ < 1 (arrivals slower than
service). If λ ≥ µ, the queue would grow without bound and no steady state would exist.
6.4 Poisson Processes
A Poisson process counts random, independent events over time (arrivals, phone calls) where the gap until the
next event doesn't depend on when the last one happened (memoryless). Defining formula:
P(N(t) = n) = (λt)ⁿ e^(−λt) / n!
This is the same formula and worked example already shown in Part 3.3 — Poisson processes are the
mathematical bridge between distribution theory and queuing theory: arrivals in a queue are modelled as a
Poisson process, and the gaps between those arrivals follow the companion exponential distribution.
PART 7: Random Numbers
7.1 Definition
Numbers showing no consistent pattern — each number in the sequence is unaffected by, and unpredictable
from, the ones before it.
7.2 Types of Random Numbers
• True random numbers — pulled from physical noise (radioactive decay, atmospheric static) — genuinely
unpredictable, not reproducible.
• Pseudorandom numbers — generated by a deterministic formula from a starting "seed"; statistically looks
random but will eventually repeat, and is fully reproducible if you know the seed. This is what computers
actually use.
7.3 Types of Random Number Generation Methods
• Congruential method — the classic linear congruential generator (LCG); worked example below.
• Quadratic congruential method — a nonlinear variant of the above.
• Mid-square method — square the seed, take the middle digits as the next number.
• Mid-product method — multiply two numbers, take the middle digits.
• Fibonacci method — generate the next number from a combination of previous numbers (Fibonacci-style
recurrence).
7.4 Properties of a Good Random Number Generator
• Near-uniform distribution
• Fast to compute
• Low memory use
• Long period before the sequence repeats
• Able to produce different streams (via different seeds)
• Non-degenerate (doesn't collapse into a short repeating cycle)
7.5 Worked Example — Congruential Method
Formula: Xₙ₊₁ = (a·Xₙ + c) mod m
Using a = 5, c = 3, m = 16, seed X₀ = 7:
n Calculation Xₙ rₙ = Xₙ/m
1 (5×7+3) mod 16 = 38 mod 16 6 0.3750
2 (5×6+3) mod 16 = 33 mod 16 1 0.0625
3 (5×1+3) mod 16 = 8 mod 16 8 0.5000
4 (5×8+3) mod 16 = 43 mod 16 11 0.6875
n Calculation Xₙ rₙ = Xₙ/m
5 (5×11+3) mod 16 = 58 mod 16 10 0.6250
The rₙ column is the stream of numbers between 0 and 1 the simulation would actually use. With m = 16 the
sequence can repeat after at most 16 steps (its period) — real generators use much larger m (e.g., 2³¹) precisely
to push that repeat point far out.
7.6 Simulating Randomness — Dice Example
To simulate a fair 6-sided die using a RND function that returns a value between 0 and 1:
X% = INT(RND × 6) + 1
RND × 6 gives a number between 0 and 6; INT() truncates it to an integer between 0 and 5; adding 1 shifts the
range to 1–6, matching a real die.
General form for an integer between P and N: INT(RND×(N+1−P)) + P
2. Four Applications of Modelling and Simulation
1. Manufacturing and production planning — simulating a factory floor to test
scheduling, due-date estimation, and raw-material ordering before committing
real money.
2. Training — flight simulators and military training systems let trainees learn on
dangerous or expensive equipment in a safe, virtual environment.
3. Traffic and network systems — simulating traffic flow, telecommunications
networks, or computer network traffic to identify bottlenecks before deploying
real infrastructure.
4. Scientific and natural systems — modelling weather patterns, population
dynamics (e.g., fisheries biology), or the spread of an epidemic, where direct
experimentation on the real system is impossible or unethical.
3. Multiplicative Congruential Random Number Generation
This is a special case of the general congruential method, which generates each new
random number from the previous one using:
Xₙ₊₁ = (aXₙ + c) mod m
If c = 0, this is called the Multiplicative Congruential Method.
If c ≠ 0, it's called the Mixed Congruential Method.
With c dropped, the multiplicative form is usually written:
rₙ = a·rₙ₋₁ (mod m)
7. Write on Random Number Generator
A random number generator (RNG) produces a sequence of numbers with no
discernible pattern — each number statistically independent of the ones before it. RNGs
are foundational to simulation because random variates (arrival times, service times,
dice rolls, etc.) must be drawn from them to make a model behave realistically.
There are two broad categories:
True random number generators — extract randomness from unpredictable
physical phenomena (radioactive decay, atmospheric noise). Not reproducible.
Pseudorandom number generators (PRNGs) — use a deterministic mathematical
formula, starting from a seed, to produce a sequence that statistically behaves
like a random one, but is fully reproducible if you know the seed, and will
eventually repeat (its period).
8. Characteristics of a Good Random Number Generator
A good RNG should:
Produce numbers that are as close as possible to a uniform distribution.
Be fast to compute.
Not require large amounts of memory.
Have a long period before the sequence repeats.
Be able to generate different streams of numbers (e.g., via different seeds).
Be non-degenerate — it shouldn't collapse into a short repeating cycle.
9. Applications of Random Numbers
Simulation and Monte Carlo methods — generating random arrivals, service
times, and events to model real-world systems (queues, inventory, traffic).
Games — dice, card shuffling, and other games of chance rely directly on random-
number generation.
Numerical integration — Monte Carlo integration uses randomly sampled points
to estimate the value of functions that are too complex (especially in many
dimensions) for standard numerical methods.
Optimization — random-walk-based methods explore a solution space (e.g., the
travelling salesman problem, engineering design optimization) to find good (if not
perfect) solutions.
Computational mathematics — e.g., Rabin's primality-testing algorithm uses
random numbers to efficiently determine whether a large number is prime.