Numerical Computing with MATLAB

This chapter describes algorithms for the generation of pseudorandom numbers with both uniform and normal distributions.
Here is an interesting number:
0. 95012928514718
This is the first number produced by the MATLAB random number generator with its default settings. Start up a fresh MATLAB, set format long, type rand, and it's the number you get.
If all MATLAB users, all around the world, all on different computers, keep getting this same number, is it really "random"? No, it isn't. Computers are (in principle) deterministic machines and should not exhibit random behavior. If your computer doesn't access some external device, like a gamma ray counter or a clock, then it must really be computing pseudorandom numbers. Our favorite definition was given in 1951 by Berkeley professor D. H. Lehmer, a pioneer in computing and, especially, computational number theory:
A random sequence is a vague notion in which each term is unpredictable to the uninitiated and whose digits pass a certain number of tests traditional with statisticians
Lehmer also invented the multiplicative congruential algorithm, which is the basis for many of the random number generators in use today. Lehmer's generators involve three integer parameters, a, c, and m, and an initial value, x 0, called the seed. A sequence of integers is defined by
The operation "mod m" means take the remainder after division by m. For...