Randomness around us
Uncertainty is an essential part of our everyday lives. Here’s a simple example: imagine you own a café that serves hot beverages and delicious pastry to around 100 customers per day.
The café is open from 9 am to 7 pm. However, the first guests could arrive at 10 one day and 9:50 the next day, it could be two customers or a dozen entering at the same time.
When we build simulation models, we want them to reflect the real world as closely as possible. For that, you would need to include randomness in your simulation.
How can you set randomness in your AnyLogic model?
Let’s take another example. You’re modeling a bank, and you’d like to know how much time a manager needs to open a new bank account for a client.
From your experience, it takes at least 10 min., most likely 20 min., and 40 min. at most. How can you model this delay? In AnyLogic, you can set a probability distribution.
Probability distribution and custom distribution
AnyLogic offers a set of probability distribution functions to model non-deterministic processes, like weather changes, product demand changes, or any other randomness. The software supports different distribution types: uniform, triangular, exponential, and more.
But what if none of the pre-set functions fits your project? You can create your custom (empirical) distribution and use it in your model.
AnyLogic internal sources of randomness
There are two types of models: stochastic and deterministic.
A deterministic model doesn’t have internal randomness. It runs with the same set of input parameters and gives the same output results. For example, if 10,000 individuals each have a 95% chance of surviving one year, we can be reasonably sure that 9,500 of them will survive.
A stochastic model, on the other hand, does have internal sources of randomness. So, each run (even with the same parameters) may give a different output.
You won’t get representative simulation results from a stochastic model if you run it once. So, you’d need to run it multiple times, even with the same input parameters. A series of simulation runs with randomness (internal, at the input parameters level, or both) is called Monte Carlo simulation.
Monte Carlo simulation results are statistically processed and typically represented as probabilities, histograms, scatter plots, envelope graphs, and more.
Read more: Internal sources of randomness in different types of AnyLogic models [PDF]
Random number generators
A computer is a deterministic device. Then, where does randomness in simulation models come from?
An application doesn’t have true randomness unless it accesses an external physical random number generator (RNG). However, we can use pseudo-randomness created with a computational RNG.
Computational RNGs are based on deterministic algorithms that produce long sequences of apparently random results, which are in fact completely determined by a shorter initial value, known as a seed, and are periodic. They are therefore called pseudo-random number generators.
Reproducible and unique experiments
Although pseudo-random number generators don’t give ‘truly random’ number streams, they have an important feature. Depending on the chosen seed, they generate a unique or the same number sequence each time you run the model.
Thanks to this feature, you can create either unique (random) or reproducible experiments with stochastic models in AnyLogic.
Reproducible experiment runs come in handy when you want to work on one scenario or when you are debugging your model. It’s better to keep model runs reproducible while developing your simulation because stochastics makes it difficult to track errors and understand what caused them.
Follow this step-by-step guide to make your model deliver either random or reproducible simulation results:
More short educational videos – in the related AnyLogic YouTube playlist.
That was our quick overview of the randomness feature in AnyLogic. If you’d like to dig deeper into the technical side of the topic, check out Chapter 15 of The Big Book of Simulation Modeling [PDF].
We regularly publish new blog articles and how-to videos on YouTube. Don’t miss out! Subscribe to our monthly newsletter and stay up to date.