
			    1. GENERATE SEQUENCES OF RANDOM NUMBERS 
			    =======================================

A set of pseudo-random number generators (RNGs) is provided as Fortran code 
(ran0.f, ran1.f, ran2.f, ran3.f, all from the popular Numerical Recipes book). 
A series of checks will be performed on these generators by producing sequences
of random numbers to which a number of statistical tests will be applied.

First compile the codes by issuing the command make to the shell (in the
Makefile, you can choose the compiler names and flags which best suit your
 needs).

Then run the code test_ran.x, which calls several times one among the RNGs and 
performs a binning of the R.N. sequence so obtained. 
For the moment being, specify nexp=1, e.g.

./test_ran.x
iran:0
number of tries:1100
number of bins:11
number of experiments:1

(ignore the warning about nexp). In this example, the histogram will be saved 
in a file named "histo-ran0_1x1100-11". You can plot it using the gnuplot 
script plot_histo.gnu that has been provided. Since the number of trials is not 
very large, for each bin the frequency obtained in this numerical experiment 
may be much different from the ideal value for a uniform deviate (i.e., 
constant between 0 and 1). How to understand if the observed fluctuations 
are statistically acceptable?



			    2. TEST THE RANDOM NUMBER GENERATORS
			    ====================================

The X^2 (Chi square) statistical test allows to give a quantitative reply to the
question if the numbers coming out from this "experiment" are distributed
according to a uniform deviate or not (see "Computational Physics" by Giordano &
Nakanishi, http://www.physics.purdue.edu/~hisao/book/). We perform a
sufficiently high number of experiments (like the one above) and, for each of
the, we compute the X^2, which we then collect in a histogram. The integral of
this histogram (i.e., the cumulative distribution of the X^2), should be the
incomplete Gamma function, P(a,x), with a equal to half the number of degrees
of freedom (in our case a=(nbins-1)/2) and x=( X^2 ) / 2.

For instance, you can perform 1000 such experiments with ran0

./test_ran.x
iran:0
number of tries:1100
number of bins:11
number of experiments:1000

The frequency of X^2 values and its integral are stored in the second and third
column of "chisq-ran0_1000x1100-11", respectively. Perform the same test for
the other three RNG and then visualize the cumulative distribution of X^2 and
compare it with P(5,X^2 / 2) using the script plot_testX2.gnu.

Even if all RNG pass successfully this simple check, this does not mean that
they are equally well performing. There are more complicated (and subtle)
statistical test that some of them may fail (see Numerical Recipes, ch. 7).

1. Distribution of points in k-dimensional spaces (see RN.pdf):
   use test_corr.x with iran=9 (general LCG) and try several values of the
   parameters (a,c,m,i0); see 2-dim. plots of pairs of R.N. (corr-ran* files)

2. Compute the average of R.N. following a very small R.N. (e.g., < 10^-5) and
   compare ran0 with the other generators

3  test_corr.x also computes the distribution of the product and of the 
   difference of two consecutive R.N. (2nd vs 1st and 4th vs 3rd columns in 
   distprod-ran* files, respectively). 
   Compare them with the theoretical distributions.

4. Using the script test_chisq2d.sh (which calls test_ran.x), you can do the X^2
   test for the 2-dim distribution of pairs of R.N. (see files chisq2d-...).
   For very large values of ntry (but much smaller than the RNG period) the ran0
   RNG should fail the test. See also chisq-... files (1D X^2 distribution):
   compare ran0 and ran1 against the other two RNG when ntry approaches to the
   period of the former two RNG (~10^9).



			    3. GENERATE NORMAL DISTRIBUTIONS 
			    ================================

There are at least two methods for generating a gaussian distribution: using 
the Box-Muller (BM) method or exploiting the central-limit (CL) theorem. Both 
methods have been implemented in ran_gauss.x. You can play with the program to
produce a sequence of normally distributed R.N. (i.e. belonging to a gaussian 
distribution with 0 average and unit standard deviation). An histogram of the
frequencies is computed and saved in a file named, e.g., "histo-gaussBM_10000":
visualize it and compare with the ideal normal distribution function, e.g.
1/sqrt(2*pi)*exp(-0.5*x**2) in the gnuplot syntax.

In the CL method you can choose the number of uniform random variables that
should be added to obtain a single gaussian distributed variable. Check how
the distribution of the sum changes as you increase that number (it should
approximate a gaussian already at a reasonably small number).

You can modify the code to perform a X^2 test for this case as well, similarly
to what has been done previously for the uniform distribution.



			    4. RANDOM WALKS IN ONE DIMENSION
			    ================================

The code ran_walk.x performs a random walk in one dimension and computes the
mean square displacement as a function of the time step. Compute the diffusion
coefficient and compare it with the theoretical value (assuming that the 
sequence of R.N. from the RNG is uncorrelated). 


