Modeling & Simulation- Lecture -6- /11/2013 Generating Pseudo-random Numbers In real life, Arrival and service times may follow an empirical distribution; we need to have a technique for generating numbers from empirical and theoretical distributions in a random fashion. In computer programming, random values make a good source of data for testing the effectiveness of computer algorithms. In simulation, random numbers are used in order to represent real-life situations. Pseudo-random numbers are uniformly distributed random numbers in [0, 1]. They are usually referred to as random numbers. By using recursive relationship to generate random numbers, this relationship as follows: ( ) ………………….. ((1)) Where , a, c and m are all non-negative numbers . For example : if = a = c = 7, m =10 then we can obtain the following sequence of numbers: 7,6,9,0,7,6,9,0,... . In the computer programming languages versions there are a built in function to generate random numbers can be used directly such as RND( ) in visual basic programming languages. Generating Stochastic Variants Random variants or stochastic variants are random numbers that follow any distribution other than the above uniform distribution in [0, 1]. In the traditional stochastic analysis of queuing systems the queues are modeled as random processes, whose state is defined by the number of entities in the system. A random process describes the probabilities of the states of the system over time. Times between arrivals and service times are modeled as random variables with certain probability distributions. To generate stochastic variants from random number, two methods can be used to achieve this purpose. First one called the Inverse Transformation method. This method is applicable only to cases where the cumulative density function can be inversed analytically. Assume that we wish to generate stochastic variants from a probability density function (pdf), f(x). Let F(x) is its cumulative density function. We note that F(x) is defined in the region [0,1]. 1 Lecturer: Hawraa Sh. Modeling & Simulation- Lecture -6- /11/2013 We explore this property of the cumulative distribution function ( cdf ) to obtain the following simple stochastic variants generator . We first generate a random number r which we set equal to F(x). That is, F(x) = r. The quantity x is then obtained by inverting F. That is, x = F-1(r), where F-1(r) indicates the inverse transformation of F. As an example: we have a pdf : f(x) = 2 x 0 ≤ x ≤ 1. Then to generate a random variants first must calculate the cdf F(x) ( ) ∫ 0 ≤ x ≤ 1. Let r be a random number , then r , √ . While, the other method called the Rejection method, the rejection technique can be used to generate random variants, if f(x) is bounded and x has a finite range, say a ≤ x ≤ b. The following steps are involved: Normalize the range of f(x) by a scale factor c so that cf(x) ≤ 1, a ≤ x ≤ b. Define x as a linear function of r, i.e. x = a + (b a) r, where r is a random number. Generate pairs of random numbers ( , ). Accept the pair and use x = a + (b a) as a random variate whenever the pair satisfies the relationship ≤ cf (a + (b a) ). As an example, we have pdf : F(x) = 2x 0 ≤ x ≤ 1. 1. Select c such that df(x) ≤ 1, c = 1/2. 2. Generate , and set x = . 3. Generate . If < cf ( ) = (1/2) 2 = then accept , otherwise , go back to step 2. 2 Lecturer: Hawraa Sh. Modeling & Simulation- Lecture -6- /11/2013 Probability Distributions Queues are modeled as random processes using the concept of the traditional stochastic analysis of the queuing networks. The system state is defined by the number of entities in the system and a random process will be used to describe the probabilities of the states of the system over time. Service times and the inter-arrival times are modeled as random variables with known probability distributions. There are many types of probability distribution categorized under two classes: continuous contain : 1. Uniform. 2. Exponential. 3. Erlang. 4. Normal. discrete contain: 1. Poisson. 2. Geometric. 3. Binomial. Sampling from Continuous Probability Distributions A) Sampling from Uniform Distribution Uniform distribution is showed in figure (1). The probability density function of uniform distribution is: ( ) { And the cumulative density function is: ( ) ∫ ∫ The inverse transformation method for generating random variants is as follows: ( ) ( ) …………….. ((2)) The expectation and variance are given by following expressions 3 Lecturer: Hawraa Sh. Modeling & Simulation- Lecture -6( ) /11/2013 ∫ ( ) ( ) ∫ ∫ ( ( )) ( ) Figure (1) The Uniform Distribution. B) Sampling from Exponential Distribution The Exponential distribution is often used as a model for durations. It is related to the Poisson distribution in that it can be used to measure the time between successes from the Poisson process. Because the exponential represents time intervals, it is a continuous, not discrete, probability distribution. Figure (2) explain this type of distributions. The probability density function of uniform distribution is: ( ) The cumulative density function is : ( ) ∫ () ∫ The inverse transformation method for generation random variants is as follows: ( ) ( We have 4 because is random variable and also ) then: Lecturer: Hawraa Sh. Modeling & Simulation- Lecture -6- /11/2013 ( )………………… ((3)) The expectation and variance are given as follows: ( ) ( ) 2.0 1.0 .0 0 1 2 3 4 5 t Figure (2) the Exponential Distribution C) Sampling from an Erlang Distribution In many occasions an exponential distribution may not represent a real life situation. For example, the execution time of a computer program, or the time it takes to manufacture an item, may not be exponentially distributed. It can be seen, however, as a number of exponentially distributed services which take place successively. If the mean of each of these individual services is the same, then the total service time follows an Erlang distribution, as shown in figure (3) ⁄ ⁄ ⁄ Figure (3) the Erlang Distribution 5 Lecturer: Hawraa Sh. Modeling & Simulation- Lecture -6- /11/2013 Generating Erlang variants can be accomplished by taking the sum of k exponential variants, , , ..., with identical mean 1/a. We have ∑ ∑ ( ∑ ) …………. ((4)) The expected value and the variance of a random variable are: ( ) ( ) D) Sampling from Normal Distribution The probability density function is: ( ) ( ) √ Where is the mean and is the standard deviation. When called standard normal distribution ( ) and then it √ Figure (4) explain the Normal distribution. 6 Lecturer: Hawraa Sh. Modeling & Simulation- Lecture -6- /11/2013 Figure (4) the Normal Distribution An alternative approach to generating normal variants (known as the direct approach) is the following. Let and be two uniformly distributed independent random numbers. Then ( ) ……………. ((5)) ( 7 ) Lecturer: Hawraa Sh.