ABSTRACT

Abstract .......................................................................................................................................... 182 7.1 Introduction .......................................................................................................................... 182

7.1.1 Chapter Outline ........................................................................................................ 183 7.2 Uniform Random Numbers .................................................................................................. 183

7.2.1 Linear Congruential Generator ................................................................................. 184 7.2.2 Multiple Recursive Generators ................................................................................. 185 7.2.3 Mersenne Twister ...................................................................................................... 185 7.2.4 Example: Uniform Random Numbers in Monte Carlo Simulations ........................ 187

7.3 Random Numbers from Nonuniform Probability Distributions .......................................... 188 7.3.1 Note on Probability Distribution, Probability Mass Function,

and Cumulative Distribution Function ..................................................................... 188 7.3.1.1 What Is a Probability Distribution? ........................................................... 188 7.3.1.2 Continuous Distributions ........................................................................... 189 7.3.1.3 Notion of Probability Mass Function in Continuous Distribution ............. 190

7.3.2 Inverse Transformation Method ............................................................................... 191 7.3.2.1 For Continuous Distribution ...................................................................... 191 7.3.2.2 Example: The Exponential Family ............................................................ 192 7.3.2.3 For Discrete Distributions .......................................................................... 192 7.3.2.4 Example of Inverse Transform Methods on Discrete Distribution ............ 193

7.3.3 Acceptance-Rejection Method ................................................................................. 194 7.3.3.1 Continuous Distribution ............................................................................. 194 7.3.3.2 Example of Acceptance-Rejection Method .............................................. 195

7.3.4 Miscellaneous Methods ............................................................................................ 196 7.3.5 Example from Continuous Distribution ................................................................... 196

7.3.5.1 Example: The Erlang Distribution ............................................................. 196 7.3.6 Example from Discrete Distribution ........................................................................ 197

7.3.6.1 Poisson Distribution ................................................................................... 197 7.4 Note on Randomness Test .................................................................................................... 198

7.4.1 Empirical Tests ......................................................................................................... 198 7.4.2 Theoretical Tests ....................................................................................................... 199

7.5 Importance of Choosing the Appropriate Random Numbers in Simulations ...................... 199 7.5.1 SimPy Basics ............................................................................................................ 199

7.5.1.1 Major Components of SimPy .....................................................................200 7.5.2 Example: A Simple Random Walk ........................................................................... 201

Computer simulations have been effectively used to predict the behaviors of many natural systems in almost all disciplines. The ability to simulate the complex real-world stochastic systems largely depends on the use of random numbers. Although we use the notion random to indicate the underlying uniform distribution, the stochastic nature of most physical systems (e.g., trafc intensity in a transport system) often exhibits the properties of various other statistical distributions (e.g., Poisson, exponential). Improper use of stochastic models leads to unrealistic simulation outcomes, which deviate far from truth. Therefore, in order to use the right randomness to appropriate stochastic models, it is of utmost importance to understand about random numbers and to learn how simulators generate these numbers. This chapter focuses on the random number generation process from statistical distributions. Although simulators usually come with some random number generator functions, the methods discussed in this chapter can be used to generate random numbers from any user-dened statistical distribution, which is often more desirable to model a natural phenomenon than the bundled random number generators of existing simulators. Utilizing Python programming language, this chapter teaches the basics of various random number generation techniques. In addition, this chapter shows how to simulate real-world scenarios by leveraging SimPy (a discrete event simulator framework for Python). Using these simple simulation examples, we will show how inappropriate random variables can affect the simulation outcomes.