The computer, as well as studying large amounts of data, is useful for **simulating**
random phenomena. The various programming languages have incorporated a **pseudo-random**
**number generator**. In **JavaScript** **Math.random()** is a pseudorandom number in the
range 0 to 1: it generates random numbers "uniformly" distributed on the interval (0,1).
See** here**.
**How** do I check this out?
An initial idea is to check it graphically; 10000 tests, 100 classes:
It is not enough to see that **runif** outputs tend to be uniformly distributed. For
example, if I want to simulate the launch of two dice or the distribution of a hand
of 10 cards, it is also necessary that an output is independent of the next. The
study of how to make a random number generator involves many areas of mathematics and
we can not focus on the topic here. Let's just see, to increase our belief that it's
a good generator, how are distributed 10000x10000 points generated with it:
To get an idea of how "runif" is done we see one of the first generators used (1980).
See** here**.
(1) A: integer **seed**; then:
(2) H = floor((259*A)/65536); A = Number(259*A-65536*H); K=Number(A/65536)
K is the generated value; then** → **(2)*
*Obviously, a finite number of points is generated: it is a periodic function.
The **period** is 16384.
Let's create 3000×3000 points with it. Let's see how they are distributed.*
*
These graphic outputs are enough to realize the limits of this generator, and the
complexity of the issue!*
*Also the standard generator is periodic, but there are 2^19937-1 numbers that
"repeat", and can be used to simulate up to 623 independent events! But (in the
JavaScript version) it is impossible to choose the seed.*
*In the simplest version, as we have seen, you can choose the seed. Generating
the same sequence of "random" numbers can be convenient in many situations
(testing an algorithm on the same sequence of values, controlling phenomena
simulations, memorizing secret encodings, …).
(incidentally, one of the people who has been busy with random number generators is
Knuth, the "dad" of the entire "Mathematics of Computing" area that deals with the
analysis of algorithms; inter alia, in 1978 he invented the typesetting system Teχ)