7 views

Uploaded by mohsindalvi87

random no. generation

save

You are on page 1of 7

Norm Matloff

February 21, 2006

c

2006,

N.S. Matloff

Contents

1

Uniform Random Number Generation

2

2

Generating Random Numbers from Continuous Distributions

3

2.1

The Inverse Transformation Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

2.1.1

General Description of the Method . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

2.1.2

Example: The Exponential Family . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

The Acceptance/Rejection Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

2.2.1

General Description of the Method . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

2.2.2

Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

Ad Hoc Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

2.3.1

Example: The Erlang Family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

2.3.2

Example: The Normal Family . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

2.2

2.3

3

Generating Random Numbers from Discrete Distributions

6

3.1

The Inverse Transformation Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

3.2

Ad Hoc Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

3.2.1

The Binomial Family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

3.2.2

The Geometric Family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

3.2.3

The Poisson Family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

1

Pseudorandom numbers can be divided by their upper bound to generate U(0. we cannot generate a true continuous random variate. Note that Seed is declared as static. Then ideally the Xi should be independent.1). [0. s. it doesn’t matter whether we talk here of (0..u. lim n→∞ D(r.. and intuitively it is plausible that they are “random. You can now see what that means. i = 1. i.and higher-dimensional versions of (2) hold.1). This certainly will give us values in (0.k) is the count of the number of i for which r < Xi < s and u < Xi+k < v. Here is an example (in pseudocode): 1 2 3 4 5 6 7 int U01() constant C = 25173 constant D = 13849 constant M = 32768 static Seed Seed = (C*Seed + D) % M return Seed/((float) M) The name Seed stems from the fact that most random number libraries ask the user to specify what they call the seed value. i = 1. n) =s−r n (1) where C(r.1).1). Suppose we call the function again and again. v. However.. from the distribution U(0. so that it retains its value between calls.” But is this a “good” approximation to a generator of U(0. There is a very rich literature on the generation of random integers.1) variates? What does “good” really mean? Here is what we would like to happen.n. 0 < u < v < 1 and integer k > 0.. k) = (s − r)(v − u) n (2) where D(r. etc.e..1 Uniform Random Number Generation The basic building block for generating random numbers from various distributions is a generator of uniform random numbers on the interval (0.1).n. 1 Since a random variable which is uniformly distributed on some interval places 0 mass on any particular point. we will generate a discrete random variate which behaves very close to U(0. • For any 0 < r < s < 1.n. with Xi being the value returned by the ith call. n. which means we would have • For any 0 < r < s < 1. u.s).. s.. commonly called pseudorandom numbers because they are actually deterministic..s. • The third.1) variates.1 How is this accomplished? Due to the finite precision of computers.v.s.1].n) is a count of the number of Xi which fall into (r. lim n→∞ C(r. 2 . The value the user gives “seeds” the sequence of random numbers that are generated.

You can assume.Equation (1) is saying that the Xi are uniformly distributed on (0. the algorithm needs to have the property that Seed can take on all values in the set {0.2 2 Generating Random Numbers from Continuous Distributions There are various methods to generate continuous random variates. or about 4 billion. We’ll introduce some of them here. and (2) and its third. where U has a U(0.1) distribution. 2. Let H denote the corresponding cumulative distribution function. It can be shown that this condition will hold if all the following are true: • D and M are relatively prime • C-1 is divisible by every prime factor of M • if M is divisible by 4. Then FX (t) = P (X ≤ t) = P (G(U ) ≤ t) = P (U ≤ G−1 (t)) = P (U ≤ H(t)) = H(t) In other words.1 The Inverse Transformation Method 2. However. Again.1). M − 1}. This makes it easy to do the mod M operation. On today’s 32-bit machines M might be 232 . How close can we come to fully satisfying these conditions? To satisfy (1). . 3 (3) .. that any reputable library package has chosen values which work well. 1. 2. then so is C-1 Typically M is chosen according to the word size of the machine.and higherdimensional versions say that the Xi are independent. without repetition (until they are all hit). X has density h. as desired. there is a rich literature on this. Set X = G(U). and let G = H −1 (inverse in the same sense as square and square root operations are inverses of each other). though..1 General Description of the Method Suppose we wish to generate random numbers having density h.. determining which values of C and D give approximate independence is something that requires experimental investigation. 2 And of course you can do your own experimental investigation on it if you wish.1. but we will not pursue it here.

Our code would then be while true: generate U1 from U(0.0/Lambda * log(1-U01()) If a random variable Y has a U(0.2. In this case.1) density.2 The Acceptance/Rejection Method 2. and take c to be the maximum value of h.2 Example: The Exponential Family For example.1) generate U2 from U(0.2 Example As an example. But if U01() returns 0. which is 3.1) distribution then so does 1-Y. pseudocode for a function to generate such random variables would be float Expon(float Lambda) return -1. using U01() instead of 1-U01().5)**2 return U1 4 . • There is some c such that h(x) ≤ cg(x) for all x.1) if U <= h(Y)/(c*g(Y)) return Y 2.) 2. consider the u-shaped density h(z) = 12(z − 0. Take our g to be the U(0. suppose we wish to generate exponential random variables with parameter λ. H −1 was easy to find.5)2 on (0. but in many other cases it is intractable. Then it can be shown that the following will generate random variates with density h: while true: generate Y from g generate U from U(0. (U01() never returns 1. which is undefined.1.1). as formulated in Section 1. With h being the exponential density above. We might be tempted to exploit this fact to save a step above. we have 1 G(u) = − ln(1 − u) λ (5) So.1) if U2 <= 4*(U1-0. Z t H(t) = λe−λs ds = 1 − e−λt (4) 0 Writing u = H(t) and solving for t. we are then faced with computing log(0). Here is another method we can use: We think of some other density g such that • We know how to generate random variables with density g.1 General Description of the Method Suppose again we wish to generate random numbers having density h.2.2.

2. we simply generate N(0. This then suggests an easy way to generate random numbers from an Erlang distribution: 1 2 3 4 Sum = 0 for i = 1. since the normal density cannot be integrated in closed form. multiply by σ and adding µ. consider the Erlang family of distributions.1) variables.. 2. a better way exists. After doing a little calculus.. We could use the acceptance/rejection method. we can see a good way to generate random numbers from a given distribution by thinking of the properties of the distribution.1) variables? The inverse transformation method is infeasible. It can be shown that this works: 1 2 3 4 5 6 7 8 9 10 11 12 13 static n = 0 static Y if n == 0 generate U1 and U2 from U(0. how do we generate N(0.1) R = sqrt(-2 log(U1)) T = 2 pi U2 X = R cos(T) Y = R sin(T) n = 1 return X else n = 0 return Y 5 .2 Example: The Normal Family Note first that all we need is a method to generate normal random variables of mean 0 and variance 1. However.3. So. such as in Section 2.1 Example: The Erlang Family For example. whose densities are given by 1 λr tr−1 e−λt . with g being p the exponential density with rate 1.3 Ad Hoc Methods In some cases..3. 2..2.r Sum = Sum + expon(lambda) return Sum where of course we mean the function expon() to be a function that generates exponentially distributed random variables. t > 0 (r − 1)! (6) Recall that this happens to be the density of the sum of r independent random variables which are exponentially distributed with rate parameter λ. we would find that we could take c = 2e/π.1. If we need random variables of mean µ and standard deviation σ.

1 The Binomial Family This one is obvious: 1 2 3 4 5 Count = 0 for I = 1.1) if U < p Count = Count + 1 return Count 3. 3.1..3 The Poisson Family Recall that if events. we can sometimes make use of special properties that we know about those distributions.3 Generating Random Numbers from Discrete Distributions 3. say arrivals to a queue..1 The Inverse Transformation Method The method in Section 2.2. for certain specific distributions.n generate U from U(0.1 works in the discrete case too.2 The Geometric Family Again.2. Let q(i) = P (X ≤ i) = i X pX (i) (7) k=0 Then our algorithm is 1 2 3 4 5 generate U from U(0.1) if U < p return Count 3. have interevent times which are independent exponentially distributed random variables with rate λ....1) I = 0 while true if U < q(I) return I I = I + 1 3. then the number of events N(t) up to time t has a Poisson distribution with parameter λt: 6 ..2 Ad Hoc Methods Again. obvious: 1 2 3 4 5 Count = 0 while true: Count = Count + 1 generate U from U(0.2.2. Suppose we wish to generate random variates X which take on the values 0.

. we can do the following: 1 2 3 4 5 6 Count = 0 Sum = 0 while 1 Count = Count + 1 Sum = Sum + expon(alpha) if Sum > 1 return Count-1 where again expon(alpha) means generating an exponentially distributed random variable. in this case with rate α. if we wish to generate random variates having a Poisson distribution with parameter α. . k! (8) So.P (N (t) = k) = e−λt (λt)k . 2. 1. k = 0.. 7 .

- qtUploaded byRushdMomani
- Binomial DistributionUploaded byAvinash Garikapati
- spring2017-600ProblemSet6Uploaded byEd Z
- ch08Uploaded byTibet Boğazköy Akyürek
- Lecture 5 - Dirac Delta Functions, Characteristic Functions, And the Law of Large NumbersUploaded byRobert Wexler
- The Binomial DistributionUploaded byolea_luna
- MGFUploaded byGauravLalsinghani
- c3_distUploaded bytarek mahmoud
- 2016CSTAT111Uploaded byAnonymous Ui8W8pexGO
- Spring 2008 Test 2 SolutionUploaded byAndrew Zeller
- Chapter 5_6377_8557_20141008172506Uploaded bySalama Badawi
- Chapter 04 W6 L1 Cont Prob Dist - Exp and Std Normal 2015 UTP C3.pdfUploaded byEvan Chin
- sol01Uploaded byMohamed Gamal
- Chapter 1Uploaded byCheng WL
- ResponsivityUploaded byPedro Reyes
- Lesson 2-08 Properties of Normal Distributions.docxUploaded byJamiefel Pungtilan
- Introduction to the Normal Distribution.pdfUploaded bywolfretonmaths
- chap15Uploaded bysankalpakash
- Ch3c Random Variables ContinuousUploaded bykhawla2789
- Stat 400 Discussion 05Uploaded bysauron_mordor
- Simple Queuing Models PDFUploaded bydrew
- Cumulative distribution functions and continuous random variables..pdfUploaded byguevaraz
- Regime-Switching State-Space Models and Their Application to Non-Stationary Time Series AnalysisUploaded byVukasin B-Cashin Jovic
- IPC2012-90255Uploaded byMarcelo Varejão Casarin
- Crash Course Birth-Death ProcessesUploaded byprabumn
- paper45.pdfUploaded byTony
- Buku Statmat I (2)Uploaded byNoviTrisnaDewi

- Http Www.livemintUploaded bymohsindalvi87
- A Smart Boring Tool for Process ControlUploaded bymohsindalvi87
- 10.1.1.215.5171Uploaded bymohsindalvi87
- e32150_484b0bc49b6f428e90c700ee928df396Uploaded bymohsindalvi87
- Style basics in WordUploaded bymohsindalvi87
- Http Www.iitkgp.ac.in Academics Paper ListUploaded bymohsindalvi87
- Global Optimization Toolbox R2013a (1)Uploaded bymohsindalvi87
- Leveraging Shainin for Quicker and More Efficient Problem Solving_ a Discussion With Ha Dao, Director at SSA & Company by Ha DaoUploaded bymohsindalvi87
- 40309461Uploaded bymohsindalvi87
- lecture13-14-15-16Uploaded bymohsindalvi87
- fdi_2013_opt_tool (1)Uploaded bymohsindalvi87

- Assignment of Criminal Justice System in BDUploaded byMd. Harun Or Rashid
- Denis_Portocarrero_Caso_#1_100402_343.docxUploaded byDenis Denzel
- A 20171126215323Uploaded byCamila Alejandra Rubio Miranda
- All TypesofRAMsUploaded byVishnu Vardhan Reddy
- El niño que agrede a sus compañeros de escuelaUploaded byGina Jimenez
- Chapter 03 - Measures of Central Tendency and Location.pdfUploaded byClemence Cruz
- A virada histórica de Bakhtin e seus antecedentes soviéticosUploaded byBruna Lopes Fernandes Dugnani
- Resumen Del Libro El Manual Del Guerrero de La LuzUploaded byRenata Hernandez
- Introduction ParcorpUploaded byMary Arlice Anne Santos
- Comentarios Informe Relaf Por Victor GiorgiUploaded byjuanmarincompositor
- Cepp Newsletter 0708Uploaded bySyed Mujtaba Ali Bukhari
- Planeamiento y Control de La ProduccionUploaded byMarco Antonio
- Liderazgo Basado en ValoresUploaded byLuis Tacuri
- 10 formas de hornear a medias tu sermón.docxUploaded bySamuel77
- Loretto at the UN - The Art of Peace at the UNUploaded byElaine Riot (ree-OH)
- Regras Basicas Da LiderancaUploaded byTatiane Nunes
- Rennes reprense ses illuminationsUploaded byAnonymous fqa7PO8o
- Los 10 pecados de empresas familiaresUploaded byEzra Crangle
- CALENDARIO 2016 Zona 19 Santa Fe Sur - FormaciónUploaded bydiegobertelli
- je comprends un texteUploaded byapi-281888957
- Manual DataCollectorUploaded byJozsef Nagy
- El Crimen Casi Perfecto - Roberto ArltUploaded byAndrea Gago
- Módulo+5Uploaded byVro Abecde
- cyberbullying.docxUploaded byLJ Vogel
- Colonist Scenario 1Uploaded byperenetre
- Control de Lectura NUploaded byElizabeth Grandon
- avaliaçao protetor solar.pdfUploaded byRogerio Lodi
- DISCIPULADO TRANSFORMADORUploaded byPedro Alberto Games Torres
- VALORACIÓN DE LA VÍCTIMAUploaded byVeTeNe
- Relacion Administracion Otras DisciplinasUploaded byHector Riveros