Methods of Generating Random Variables

Student project for ECE302

by Zhenming Zhang



1. Generating uniformly distributed random numbers between 0 and 1: U(0,1)

a) Linear Congruential Generators

A linear congruential generator has the property that numbers are generated according to

Zi = (aZ(i-1) + c) mod m

where m, a, c and Z0 are non-negative integers. We say that m is the modulus and that Z0 is the seed. The sequence that we obtain clearly satisfies 0<= Zi < m. In order to generate pseudo-random numbers, U1,...,Un,..., we set Ui = Zi/m. Note that Ui is inside(0,1) for each i.

We now act as though the Ui's constitute an independent sequence of U(0,1) random variables.


b) Using MATLAB Functions

rand(n)

r = rand(n) returns an n-by-n matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval (0,1). r = rand(m,n) or r = rand([m,n]) returns an m-by-n matrix.

Example: rand(1, 5)

ans = 0.8147 0.9058 0.127 0.9134 0.6324



2. Generating Normal Random variables

a) Box-Muler method

If Z- N(0, I2) then

R=(Z1)^2 + (Z2)^2 is exponentially distributed with mean 2.

Given R, the point(Z1, Z2) is uniformly distributed on the circle of radius sqrt(R) centered at the origin.

Generate R and choose a point uniformly from the circle of radius sqrt(R). (r = -2log(U1))

To generate a random point on a circle, generate a random angle uniformly between 0 and 2pi and map the angle to a point on the circle.

The random angle can be generated as V=2*pi*U2 and the corresponding point has coordinates (sqrt(R)*cos(V)), (sqrt(R)*sin(V)).

b) Using MATLAB Functions

normrnd(mu, sigma)

r=normrnd(mu, sigma) generates random numbers from the normal distribution with mean parameter mu and standard deviation parameter sigma. mu and sigma can be vectors, matrices, or multidimensional arrays that have the same size, which is also the size of R. A scalar input for mu or sigma is expanded to a constant array with the same dimensions as the other input.


References:

Martin Haugh, 2004, " Generating Random Variables and Stochastic Process" Retrieved from [1]

Ozgur KARAYALCIN, 2007, "Generating Random numbers and Random variables", Retrieved from [2]

MathWorks Reference Retrieved from [3]


Back to ECE302 Spring 2013, Prof. Boutin

Alumni Liaison

Questions/answers with a recent ECE grad

Ryne Rayburn