ABSTRACT

This chapter presents several examples of random processes simulations that use the random number generators. It provides an example of a ball bouncing on a peg board, discuss a coin flipping simulation, and finally simulate a virus spreading. Simulations involving random outcomes are often called Monte Carlo simulations. It is left as an exercise for a reader to show that just with simple variable renaming, this code calculates the difference between the numbers of summed heads and tails outcomes for a given number of flips of an unbiased coin. Imagine a game in which someone flips a fair coin. If the coin falls on heads, reader receives quadruple his bet; otherwise, reader owes his bet to the other player. The chapter utilizes the array calculation capabilities of Matrix Laboratory to avoid a loop over each game realization. The one-dimensional array member_stat keeps track of the cycle colony status.