1. Random Sampling
a. Pseudorandom numbers
Random numbers are a sequence of numbers, , lying in the interval (0,1). There is no pattern in the progression of the numbers, nor is any number in the sequence related to any other number by a continuous function. There are statistical tests for randomness in a sequence of numbers but we won’t bother with them here.
The operation of a computer is deterministic, so truly random numbers cannot be generated by a computer program. However, sequences can be generated that appear to be random in that the sequence passes some of the statistical tests for randomness. Such a sequence of numbers is called pseudorandom.
Here is an algorithm for generating a sequence of pseudorandom numbers:
where a, c and m are integers and mod( ) is the modulus function. The pseudorandom number uniformly distributed in the interval (0,1) is zi.
In MatLab® , this looks like the following: [Using the built-in remainder function (rem).]
x = xo
for i=1:100
x1 = rem(a*x+c,em);
z = x1/em
x = x1;
end
This process generates a sequence of numbers {zi} that have some properties of random numbers, but in fact the sequence repeats itself—it’s periodic. The exact sequence depends on the initial value, xo, called the seed. Usually, m is a large integer, commonly a power of 2. The numbers c and m can have no common factor (c can be zero) while a is a multiple of a prime factor of m + 1. The period of the sequence is m, which is why m needs to be large. For instance, we might take , c = 0 and a = 16807.
On the other hand, MatLab® has built-in random number generating functions, shown in Table 3-2.
b. Intervals
Suppose we want our pseudorandom numbers to lie in the interval (a,b) rather than (0,1). This is easily done by scaling, or mapping onto the desired interval. Say , then will lie in the interval (a,b).
c. Distributions
The example random number generator mentioned above produces numbers uniformly distributed in (0,1). This means that is (0,1) were divided into equal subintervals, an equal number of random numbers is expected in each of those subintervals. The probability of the next random number in the sequence falling in a particular subinterval is the same for all the subintervals spanning (0,1).
It is possible to form sequences of pseudorandom numbers which obey some other distribution function, such as Poisson or Gaussian, etc. We won’t get into that here.
Share with your friends: |