# 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. There are several random number generators. # # Let's look at the generator used in JavaScript, on which the "dadi" and "n. casuali" # scripts present here are based. # With the last script, I generate 100, 500 and 2500 numbers between 0 and 1 with 3 # decimal places and represent them with the "histograms" script using 10 intervals: ## Uniformly distributed numbers between 0 and 1 are generated. # I can easily verify that as the number of tests increases, the histogram tends to # flatten. # It is not enough to see that the 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); # if I generate 3000 points I have:
# These graphic outputs are enough to realize the limits of this generator, and the # complexity of the issue! # The usual generators only a finite number of points produce: they are periodic # functions. This generator after 16384 number produce the same sequence of number. # Also the actual standard generator (which dates back to 1998) is periodic, but with # it ther are 219937-1 numbers that "repeat", and can be used to simulate up to 623 # independent events! # Is is possible to choose the initial number: 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χ # For more information about random number generators see here.