© Irfan Turk 2019
I. TurkPractical MATLABhttps://doi.org/10.1007/978-1-4842-5281-9_5

5. Applications in Simulation

Irfan Turk1 
(1)
Nilufer, Bursa, Turkey
 

In this chapter, we first cover how to generate random numbers. Then, flipping a coin, rolling a pair of dice, random walking, and traffic flow topics are covered. In each section, I provide illustrations of the relevant programming ideas and explain them when necessary.

Random Number Generation

To create sequences of pseudorandom numbers in MATLAB, one of the rand, randn, or randi commands can be used (Table 5-1). We can use the rng function to control the repeatability of the numbers.
Table 5-1

Random Generating Functions

Function

Explanation

Example

rand(n)

rand(n,m)

Creates uniformly distributed pseudorandom ...

Get Practical MATLAB: With Modeling, Simulation, and Processing Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.