8 1 Random Number Generator It is always
8. 1 Random Number Generator • It is always impossible to make perfect measurements in the real world. Some measurement noise will always be associated with each measurement. Most engineering designs are tested by running simulations of the operation of the system before it is ever built. The simulation input data supplied to the models must be corrupted by a simulated measurement noise. • Computer generated "Random Numbers" are used in many applications. Indeed, there is a whole set of numerical "Monte Carlo" techniques based on them. This page describes how (most) random number generators work and most importantly it lets you design and test your own random number generator. Most random number generators generate a sequence of integers by the following recurrence:
• x 0 = given, x • The notation mod N means that the expression on the right of the equation n+1 = P 1 xn + P 2 (mod N) n= 0, 1, 2, . . . (8. 1. 1) is divided by N, and then replaced with the remainder. • To understand the mechanics consider the following simple Example. • x 0 =79, N = 100, P 1 = 263, and P 2 = 71 x 1 = 79*263 + 71 (mod 100) = 20848 (mod 100) = 48, x 2 = 48*263 + 71 (mod 100) = 12695 (mod 100) = 95, x 3 = 95*263 + 71 (mod 100) = 25056 (mod 100) = 56, • x 4 = 56*263 + 71 (mod 100) = 14799 (mod 100) = 99, The parameters P 1, P 2, and N determine the characteristics of the random number generator, and the choice of x 0 (the seed ) determines the particular sequence of random numbers that is generated.
• If the generator is run with the same values of the parameters, and the same seed, it will generate a sequence that's identical to the previous one. In that sense the numbers generated certainly are not random. They are therefore sometimes referred to as pseudo random numbers. The simulated noise is usually produced by a random number generator. Consider the following equation: •
• Where n 1 is a nonnegative integer. ni+1 will be a number between o and 134, 455 because the modulo function. Also, ni+1 can be fed into the equation to produce a number ni+2 that is also between 0 and 134, 455. This process can be repeated to produce a series of number in the range 0 to 134, 455. Eq. (8. 1. 2) can be used for simple random number generator with a uniform distribution. The Random umber will be based on the following Equation.
• Where ni is a number in the range 0 to 134, 455 produced by Eq. (8. 1. 2). The particular sequence produced by Eqs. (8. 1. 2) and (8. 1. 3) will depend on the initial value of n 0 (called the seed) of the sequence.
8. 2 Monte Carlo integration Consider a square dart that contains a circular region in its • interior. Assume that you throw darts at the board and are accurate enough that all of the darts hit the board, but with location that are distributed randomly over the surface of the board. The probability that a dart lands in any particular region is then proportional to the area of that region. Hence , the fraction of darts that land inside the circular region will be proportional to the ratio of the area of the circle to the area of the entire board
This observation is the basis of the Monte Carlo method for evaluating an integral. • Here the integral of interest is just the area of the circle. To simulate this dart-throwing process , we use random numbers to select the places where the darts strike the board. Let us consider quarter of circle. The program is concerned the board lies in the range 0<=x<=1. 0<=y<=1. 0. x and y Are random from this range. We then test to see if this point (x, y) satisfies the • condition y<=sqrt(1 -x 2), that is , if the point lies within the circle. This process is repeated for a large number of such points Ntotal , and we calculate how many of the darts land within the quarter circle, Nunder. The area under this curve is Nunder/Ntotal times the area of the square , and the area of the square is unity The method described above can be adapted to calculate the area under any function , and you can also calculate volumes or hyper –volumes of almost any shape as long as there are easily implement able ways of checking if a randomly generated point lies inside or outside of the region of interest. •
• A simple Monte Carlo integration implementation is thus Where xi are the N points chosen randomly from the • interval (a, b) with uniform probability The Monte Carlo method does not depend on the • dimensionality of the integral; in any dimension its error is of order 1/sqrt(Ntotal)
- Slides: 9