Introduction to Simulink with Engineering Applicatioins, Second Edition

Appendix C: Random Number Generation

This appendix is a short tutorial on Random Number Generation. An example is presented to illustrate the sequence which most random generators use.

C.1 Random Numbers

Random numbers are used in many applications. Random number generation is the production of an unpredictable sequence of numbers in which no number is any more likely to occur at a given time or place in the sequence than any other. Truly random number generation is generally viewed as impossible. The process used in computers would be more properly called pseudorandom number generation.

C.2 An Example

A typical random number generator creates a sequence in accordance with the following recurrence:

(C.1)

where mod N is used to indicate that the sum P 1x n + P 2 is divided by N and then is replaced by the remainder of that division. The values of x 0 (seed), P 1, P 2, and N must be specified. As an example, let


then, in MATLAB notation

x0=1, P1=281, P2=123, N=75x1=P1*x0+P2, y1=mod(x1,N)x2=P1*y1+P2, y2=mod(x2,N)..........xn=P1*y(n-1)+P2, yn=mod(xn,N)

To find the sequence of numbers for the random number generator, we use the following MAT-LAB script:

P1=281; P2=123; N=75; x=1:100; y=zeros(100,2);y(:,1)=x';y(:,2)=mod((P1.*x+P2),N)';fprintf(' x y\n');disp('------');fprintf('%3.0f\t %3.0f\n',y')<span class="beginpage"> pagenum="C-2"><a name="2198"></a><a name="IDX-C-2"></a></span>

MATLAB outputs the following table:

  x   y  <i class="emphasis">------</i>  1  29  2  10  3  66  4  47  5  28  6   9  7  65  8  46...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Logic Counters
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.