You are on page 1of 7

CHAPTER 2

Random Number Generation and Random Varieties


There are number of problems which cannot be modeled by simple statistical mathematical techni!ues or it is "ery difficult to model by these techni!ues# $eauty of a model lies% not in its comple&ity but in its simplicity# 'or e&ample if one has to ma(e model of a weapon system% techni!ues of pure mathematics are not so handy and one has to opt for other techni!ues# )n this chapter we will be discussin* a different techni!ue which is also !uite "ersatile in sol"in* "arious problems where e"ents are random# This techni!ue is called +onte Carlo simulation# Computer simulation is one of the most powerful techni!ues to study "arious types of problems in system analysis# The conceptual model is the result of the data *atherin* efforts and is a formulation in one,s mind -supplemented by notes and dia*rams. of how a particular system operates# $uildin* a simulation model means this conceptual model is con"erted to a computer model -simulation model.# +a(in* this translation re!uires two important transitions in one,s thin(in*# 'irst% the modeler must be able to thin( of the system in terms of modelin* paradi*m supported by the particular modelin* software that is bein* used% second% the different possible ways to model the system should be e"aluated to determine the most efficient yet effecti"e way to represent the system# +any problems which cannot be sol"ed by mathematical methods can be sol"ed by +onte Carlo simulation Properties of Random Numbers A se!uence of random numbers has two important statistical properties# /# 0niformity and% 2# )ndependence# Each random number is an independent sample drawn from a continuous uniform distribution between an inter"al 1 and /# Probability density function of this distribution is *i"en by%

Test for the Uniformity of Random Numbers: )f the inter"al between 1 and / is di"ided into n e!ual inter"als and total of m -where m > n. random numbers are *enerated between 1 and / then the test for uniformity is that in each of n inter"als% appro&imately -m/n. random numbers will fall#

/*program for generating pseudo uniform random numbers by Congruential method*/

#include <iostream.h> #include <stdlib.h> #include <math.h>

main( ) { int a,b,k,j,i,m,nn,seed,r[50]; cout<<\nEnter the integer value of a,b,m, leave space between a,b,m; cin>>a>>b>>m; cout<<\nEnter the integer value of seed; cin>>seed; cout<<\nEnter the number of Random numbers to be generated; cin>>nn; r[0]=seed; for(i=0; i<=nn; ++i) { r[i]=(a*r[i-1]+b)%m; cout<<r[i]; } /* Program ends*/ 2

Which are the Good Random Numbers? )t should ha"e a sufficiently lon* cycle% without repetition# A set of random numbers should be able to repeat# This means% *i"en the same parameters and seed "alue% set of random numbers should be same# Generated random numbers should be independent and uniform# Random number *enerator should be fast and cost effecti"e# )t should be platform independent Random - Variate Generation Introduction: This chapter deals with procedures for samplin* from a "ariety of widely used continuous and discrete distributions# Here it is assumed that a distribution has been completely specified% and ways are sou*ht to *enerate samples from this distribution to be used as input to a simulation model# The purpose of the chapter is to e&plain and illustrate some widely used techni!ues for *eneratin* random "ariates% not to *i"e a state of3the3art sur"ey of the most efficient techni!ues# Techniques: )NVER4E TRAN4'5R+AT)5N TECHN)60E ACCEPTANCE3RE7ECT)5N TECHN)60E In erse Transform Technique: The in"erse transform techni!ue can be used to sample from e&ponential% the uniform% the 8eibull% and the trian*ular distributions and empirical distributions# Additionally% it is the underlyin* principle for samplin* from a wide "ariety of discrete distributions# The techni!ue will be e&plained in detail for the e&ponential distribution and then applied to other distributions# )t is the most strai*htforward% but always the most efficient# Techni!ue computationally 9#/#2 Uniform !istribution: Consider a random "ariable : that is uniformly distributed on the inter"al ;a% b<# A reasonable *uess for *eneratin* : is *i"en by : = a > -b 3 a. R 3333333333333333333333333-/. ;Recall that R is always a random number on -1%/.# The pdf of : is *i"en by f -&. = / - b3a .% a ? & ? b 1% otherwise

The deri"ation of abo"e E!uation follows steps / throu*h @ 4tep /# The cdf is *i"en by '-&. = 1% & A a - & B a . - b Ba .% a ? & ? b /% & C b 4tep 2# 4et '-:. = -: 3 a. -b 3a. = R 4tep @# 4ol"in* for : in terms of R yields : = a > -b D a.R% which a*rees with E!uation -/. "cceptance Re#ection $ethod of Random Number Generation This method is sometimes called% rejection method. This method is used for *eneratin* random numbers from a *i"en non3uniform distribution# $asically this method wor(s by *eneratin* uniform random numbers repeatedly% and acceptin* only those that meet certain conditions# These conditions for acceptin* the uniform random numbers are so desi*ned that the accepted random numbers follow the *i"en distribution# 'or the reEection method to be applicable% the probability density function f -x. of the distribution must be non Fero o"er an inter"al% say - a% b.# Get function f -x. is bounded by the upper limit fma& which is the ma&ima of f -x.#

The re#ection method consists of fo%%o&in' steps: /# Generate a uniform random number u lyin* between -1% /.# Get us define p as p = a > - b B a .u This means p lies between a and b# 2# Generate another uniform random number v lyin* between -1% /.# Get us define q = fma&.v#

@# )f q C f -y.% then reEect the pair -u% v.% otherwise accept u as the random number followin* the distribution f -x.# This method wor(s as all the random numbers accepted lie below the cur"e y = f -x.# 5nly restriction is that this method wor(s for random number in a limited area% which is bounded by lower and upper limits# )n this method one has to *enerate lar*e number of uniform random numbers which may ta(e more time in *eneratin* the desired random numbers# )n case cur"e f -x. does not ha"e a ma&ima viz., cur"e is conca"e upward% then abo"e step no#2 becomes q = f -b.#v% rest of the procedure is same -'i*# H#@.# )n case there are more than one cusp in the probability distribution function% hi*hest of ma&imum "alues can be ta(en as fma& -see 'i*# H#H.#

"cceptance-Re#ection Technique: 4uppose that an analyst needed to de"ise a method for *eneratin* random "ariates% :% uniformly distributed between / H and /# 5ne way to proceed would be to follow these stepsI 4tep/I Generate a random number R# 4tep 2aI )f R C / H% accept : = J% then *o to step @# 4tep 2bI )f R A / H% reEect J% and return to step /# 4tep @I )f another uniform random "ariate on ;/ H%/< is needed% repeat the procedure be*innin* at step /# )f not% stop# Each time step / is e&ecuted% a new random number R must be *enerated# 4tep 2a is an KacceptanceL and step 2b is a MreEectionM in this acceptance reEection techni!ue# To summariFe the techni!ue% random "ariates -R. with some distribution -here uniform on ;1%/<. are *enerated until some condition -R C / H. is satisfied# 8hen the condition is finally satisfied% the desired random "ariate% : -here uniform on ;/ H%/<.% can be computed -: = R.# This procedure can be shown to be correct by reco*niFin* that the accepted "alues of R are conditioned "aluesN that is% R itself does not ha"e the desired distribution% but R conditioned on the e"ent OR C / H2 does ha"e the desired distribution# To show this% ta(e / H A a A b A /N then P - a A R ? b P # ? R ? / . = P -a A R ? b . P - # ? R ? / . = b B a @ H -9#2Q. which is the correct probability for a uniform distribution on ;/ H% /<# E!uation -9#2Q. says that the probability distribution of J% *i"en that R is between / H and / -all other "alues of R are thrown out.% is the desired distribution# Therefore% if / H A R A /% set : = R#

You might also like