Building Simulation Models, Explained with Examples

UPI Study › Courses › Quantitative Analysis › Free lessons › Lesson 3.2 Free with a free account

Building Simulation Models

Quantitative Analysis · Chapter 3: Simulation and Monte Carlo MethodsSection 3.2 · lesson 10 of 5514 min · free with a free account

← Simulation for Business Problem-SolvingNext lesson: Monte Carlo Simulation →

Earn 3 college credits for Quantitative AnalysisRecommended for credit by NCCRS · Math 250 · self-paced · one payment, lifetime access

In this lesson

Random numbers, probability distributions, and the difference between static and dynamic approaches.

  • Explain how pseudo-random numbers are generated and why seeding matters
  • Choose the right discrete or continuous distribution for a variable
  • Apply the inverse transform method to sample from any invertible CDF
  • Distinguish static from dynamic simulation, and run one by hand

Transcript

Everything said in the video, section by section (2,038 words). Read along, or search it.

Simulation and Monte Carlo Methods · Section 3.2

Building Simulation Models

Welcome to section three point two, Building Simulation Models. In the last section you met simulation as an idea. Now we open the box and look at the machinery. There are three pieces of machinery, and every simulation you will ever build uses all three. First, a way of manufacturing randomness inside a machine that has none. Second, a set of probability distributions, chosen to match the uncertainty you actually face. Third, a decision about whether time belongs in the model at all. By the end you will explain how pseudo-random numbers are made, and why the seed matters. You will pick the right distribution for a variable, and sample from it with the inverse transform. And you will run a small inventory simulation entirely by hand. That exercise makes everything else click.

Randomness As Raw Material

Why Every Simulation Starts With Uncertainty

Simulation is the art of building a working miniature of a real system. You let the miniature run, many times, under many conditions, and watch what it does. At the heart of every simulation sits randomness. Customers do not arrive at fixed intervals. Demand does not equal forecast. Machines do not fail on schedule, however carefully the maintenance plan is written. To imitate that uncertainty inside a computer, you need three things. A controlled way to generate randomness, in a machine that is strictly deterministic. A vocabulary of distributions, describing the kinds of randomness that actually show up. And a discipline for deciding whether time matters in your model, or not. We take those in order, and finish with a full simulation done by hand.

Pseudo-Random Numbers

A Deterministic Machine Faking Chance

Start with an awkward fact. Computers are strictly deterministic, so the same input always gives the same output. How, then, do they produce random numbers? They do not. They produce pseudo-random numbers. These sequences pass statistical tests for uniformity, independence and lack of pattern, yet come from a fixed recipe. The classic recipe is the linear congruential generator. The next number equals a, times the current number, plus c, all taken modulo m. Start from a seed, and it grinds out integers from zero up to m minus one. Divide each by m, and you land in the interval from zero to one. With well-chosen constants the period is enormous, and the statistics look genuinely random. Modern generators, the Mersenne Twister, P C G and Xoshiro, use richer mathematics on the same principle. Now the part that sounds like a weakness and is actually the point. Because the generator is deterministic, the same seed replays the same sequence, exactly. That makes a run reproducible, testable by an outside auditor, and debuggable when trial twelve hundred and forty-seven misbehaves. In regulated work, record the seed with the model. A result that cannot be reproduced is no result at all.

The Universal Foundation

From Seed to Sample

Here is the pipeline every simulated number travels down. A seed goes in, a deterministic recipe turns it into a stream, uniform between zero and one. Then a transform presses that stream into whatever shape the model needs. Every random sample in a simulation is built from those uniform numbers. A normally distributed stock return, a Poisson-distributed arrival count, all of them start there. Think of the uniform stream as raw material, and distributions as the shapes you press it into. Before computers, analysts drew that raw material from printed random number tables. The RAND Corporation published the famous one in nineteen fifty-five, called A Million Random Digits. Pick a starting row and column, then read digits in one direction. Pairs for two-digit numbers, triples for three.

The Vocabulary

Which Distribution Describes This Variable?

Choosing the distribution for each variable is one of the most consequential modeling decisions you make. Get it wrong, and the whole simulation tilts quietly in one direction. There are two families. Discrete for countable outcomes, continuous for any value in a range. The discrete uniform gives every outcome the same chance, like a fair die, but real counts rarely behave that way. The binomial counts successes in a fixed number of independent trials, each with the same probability. Think defective items in a batch, or conversions from a fixed mailing list. The Poisson counts events in a fixed interval, occurring independently at an average rate. It is the default starting point for arrivals: customers, calls, defects, accidents. On the continuous side, the normal is the bell curve, set by a mean and a standard deviation. The exponential models time between successive Poisson events, skewed right, so short gaps are common. The triangular needs a minimum, a most likely value and a maximum, which suits expert judgement with no data. The lognormal, whose logarithm is normal, is strictly positive and skewed, fitting prices, incomes and repair costs.

Inverse Transform

Turning One Uniform Number Into Any Distribution

So you have a uniform number between zero and one. How do you turn it into an exponential sample? The inverse transform method gives a clean, general recipe. Take the cumulative distribution function of the target. It maps a value to a probability between zero and one. Run it backwards, and the inverse maps a probability back to a value on the original scale. That is the whole trick. The sample equals F inverse, evaluated at your uniform number. Picture the C D F curve. Draw a horizontal line at the height of your uniform number. Where it meets the curve, drop straight down, and read the sample off the horizontal axis. Take the exponential. Its C D F is one minus e to the minus lambda x. Invert that, and the sample is minus the natural log of one minus u, divided by lambda. Set lambda to one, and let u be zero point six eight. One minus that is zero point three two. Its negative natural log is about one point one four, and that is your sample. This works whenever the C D F inverts in closed form. For the normal it does not, so software goes numerical.

Fitting The Data

Do Not Assume a Distribution - Test It

Choosing a distribution is rarely pure assumption. You test the fit against real data, in four steps. First, plot a histogram, so you can see the shape you are dealing with. Second, propose candidates: normal, exponential, triangular, or anything else plausible. Third, estimate the parameters, by maximum likelihood or the method of moments. Fourth, apply a goodness-of-fit test. That is the step people skip, and the one that catches the mistake. Two tests do most of the work. The chi-square test groups observations into bins, then compares observed counts with expected counts. It sums the squared differences, each scaled by the expected count, and suits discrete or binned data. The Kolmogorov-Smirnov test needs no bins, comparing your empirical C D F with the candidate C D F. Its statistic is simply the largest vertical distance between those two curves. Either way, a small p value says the candidate fits poorly. Try a different one.

Static Vs Dynamic

Snapshots, or a System Evolving in Time?

Not every simulation cares about time. Is the model a pile of independent snapshots, or a system evolving as events fire? Static simulation, usually called Monte Carlo, is the pile of snapshots, with no time step at all. Give every input a distribution, run the model thousands of times, and study the output distribution. Take project cost estimation. Labour cost is triangular: one million low, one point four likely, two point one high. Material cost is normal, with a mean of three million and a standard deviation of four hundred thousand. Contingency claims are Poisson with a rate of two, each claim costing a hundred thousand. Each trial samples once from every distribution and records a total, over ten thousand trials. Read the ninetieth percentile off the resulting distribution, and that is your budget reserve. Dynamic simulation carries a state: queue lengths, inventory levels, machine status, all changing over time. Time advances from one event to the next. An arrival, a breakdown, a shipment received. Think of a bank. Arrivals are Poisson, interarrival times exponential, teller service times lognormal. Here is the counter-intuitive part. A clump of arrivals causes a backup that lingers long afterwards. The same total, spread evenly, produces no queue at all. A static model cannot see that.

Choosing An Approach

Five Considerations That Settle It

Five considerations settle the choice between the two approaches. First, the nature of the problem. No time element, outcome just a function of the inputs? Go static. If the system evolves, and sequence and timing matter, go dynamic. Typical uses split cleanly: project cost, risk analysis, portfolio net present value, sensitivity studies. Queuing, manufacturing lines, hospital flow and supply chains all sit on the dynamic side. A static trial is one calculation, so it is cheap. A dynamic trial runs many events and tracks complex state. For precision, static accuracy improves with the square root of the number of trials. Dynamic precision depends on run length, and on how many replications you take. The tools differ: Excel, at Risk, Crystal Ball and Python on the static side. Arena, Simul eight, Any Logic and Sim Pie on the dynamic side. When in doubt, ask one question. Does the sequence of events change the answer? If yes, dynamic.

Worked Example

A 10-Period Inventory Simulation

Now we tie every idea together in one worked example, done entirely by hand. A small retailer stocks a single product, and demand each period is uncertain. We simulate ten periods under a fixed policy. Starting inventory is twenty units, the order quantity is fifteen, and the reorder point is eight. If ending stock falls to eight or below, an order goes out. Lead time is one period, so an order placed at the end of one period arrives two periods later. Shortage costs five dollars for every unit of demand you cannot meet. Holding costs one dollar per unit of ending stock, each period. Demand follows a discrete distribution from historical records, running from two units up to nine. Two, three, eight and nine each carry a probability of zero point one zero. Four through seven carry zero point one five. The cumulative column turns a random number into a demand. Two takes zero zero to zero nine, four takes twenty to thirty-four. Notice what those ranges really are: the inverse transform, applied by hand to two-digit uniform numbers.

Period By Period

The Simulation Log

We draw ten two-digit random numbers, reading straight across one row of the table. Forty-three, seventy-eight, twenty-four, eighty-five, fifty-two, ninety-one, zero six, sixty, seventy-four and thirty-nine. Through the cumulative ranges those become demands of five, seven, four, eight, six, nine, two, six, seven and five. Now walk the periods in order, because the state carries forward. Period one opens at twenty, demand is five, and we end on fifteen. No order. Period two opens at fifteen, demand is seven, and ending stock lands exactly on eight. Eight is the reorder point, so an order for fifteen units goes out. Period three opens at eight and ends on four, but that order is already in transit. Period four opens at nineteen: four units left over, plus the fifteen that have just arrived. Demand of eight leaves eleven. Period five ends on five, so another order goes out. And period six is where it gets interesting. Stock on hand is five, demand arrives at nine. We sell five, and four units of demand go unmet. Timing caused that stockout, not average demand. The replenishment simply had not landed yet.

Results

One Run, and What It Cannot Tell You

Add up the run, and you get the performance summary. Total demand across the ten periods was fifty-nine units. We fulfilled fifty-five, and fell four short. That is a service level of ninety-three point two per cent. Average ending stock was seven point three units, so holding cost seventy-three dollars at a dollar each. The four-unit shortage, at five dollars each, added twenty dollars. Ninety-three dollars in all. Look again at where that shortage came from. Demand spiked to nine against a beginning stock of five. The order had gone out in period five, but the lead time held it back. Sequence and timing produced the stockout, and a static model would never have seen it. Now the caution that matters most. This is one run, one trajectory through one demand stream. It shows you the mechanics, and it proves nothing at all about the policy. To test a reorder point of eight, repeat the run hundreds of times with different seeds, then pool the results. A single run shows the mechanics. Many runs reveal the behaviour under uncertainty.

About Quantitative Analysis at UPI Study

Quantitative Analysis (Math 250) is a self-paced online course of 55 video lessons in 13 chapters, from decision analysis and simulation to inventory and queuing models, project scheduling, linear programming and transportation models. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: Statistics vs Quantitative Analysis

Why take it here

Why students take Quantitative Analysis with UPI Study

Decide with numbersQuantitative Analysis teaches the models managers use to decide under uncertainty: decision trees, simulation, inventory and queuing models, project scheduling and linear programming. It is part of many business, management, operations and supply-chain programs.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

Quantitative Analysis carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About Building Simulation Models

What are pseudo-random numbers, and why does the seed matter in simulation?
Pseudo-random numbers come from a deterministic formula but pass statistical tests for uniformity and independence. A classic recipe is the linear congruential generator, X_{n+1} = (aX_n + c) \bmod m, divided by m to give values between 0 and 1. Because the recipe is deterministic, the same seed reproduces the same sequence, which makes runs repeatable, auditable and easier to debug. Record the seed with the model.
How does the inverse transform method generate random samples?
The inverse transform method feeds a uniform random number u between 0 and 1 into the inverse of the target distribution's cumulative distribution function, x = F^{-1}(u). For an exponential distribution, x = -\ln(1-u)/\lambda. With \lambda = 1 and u = 0.68, the sample is -\ln(0.32) \approx 1.14. It works whenever the CDF can be inverted in closed form; for the normal, software uses numerical methods.
Which probability distribution should you use for a simulation input?
Choose based on what the variable describes. The Poisson suits counts of independent events in an interval, such as arrivals; the exponential models time between those events; the binomial counts successes in a fixed number of trials; the triangular needs only a minimum, most likely and maximum value, useful when relying on expert judgment; and the lognormal fits positive, right-skewed quantities like prices or repair costs. Confirm the fit with goodness-of-fit tests.
What is the difference between static and dynamic simulation?
Static simulation, usually called Monte Carlo, has no time element: each trial samples every input once and computes an outcome, as in project cost estimation. Dynamic simulation tracks a system's state, such as queue length or inventory level, as events occur over time. Choose dynamic when the sequence of events changes the answer; for example, a clump of arrivals can create a lingering queue that evenly spaced arrivals would not.

About the Quantitative Analysis course

How many college credits is Quantitative Analysis?
Quantitative Analysis (Math 250) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Quantitative Analysis cost and what is included?
$250, paid once, with lifetime access: all 55 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Quantitative Analysis take?
It is self-paced with no deadlines. The 55 lessons total about 11 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in Quantitative Analysis.

55 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

Quantitative Analysis
3 credits · NCCRS
Enroll →