# RANNUM: help and advice

Consult the reference manual for further details and worked examples.
W.G.Bardsley, University of Manchester, U.K.

Pseudo-random numbers

Truly random numbers cannot be generated by computers, but it is possible to generate finite sequences of pseudo-random numbers that, for many purposes, can be used as if they were random numbers. First uniform numbers on (0,1) are generated then they are transformed as required.

A seed is required to start the algorithm, and you can choose this or select it randomly (using clock-time). Note that the same integer seed generates the same sequence. You are provided with a selection from several continuous or discrete distributions. The continuous ones generate real numbers but the discrete ones yield integers. After choosing a distribution you input the necessary parameters.

If you write n numbers to a file it will have a title, then n 1 (indicating a n by 1 matrix) followed by the n numbers. Then there will be m, indicating m further text lines.
Use program EDITMT to edit such files.

Distributions and their density/mass functions

Cauchy: parameters A and B, B > 0

        f(x) = 1/{B*pi*[1 + ((x - A)/B)^2]}

Chi-square: N degrees of freedom, N > 0, x > 0

        f(x) = [x^(N/2 - 1)]*exp(-x/2)/{[2^(N/2)]*(N/2 - 1)!}

Negative exponential: mean A, A > 0, x > 0

        f(x) = (1/A)*exp(-x/A)

Gamma: parameters A and B, A > 0, B > 0, x > 0

        f(x) = [x^(A - 1)]*exp(-x/B)/{(B^A)*(A - 1)!}
        E(x) = A*B
        V(x) = A*B^2

Logistic: mean A, spread B, B > 0

        f(x) = exp[(x - A)/B]/{B*(1 + exp[(x - A)/B])^2}

Lognormal: parameters A and B, B > 0, x > 0

        f(x) = (1/[sqrt(2*pi)*B*x])*exp{-0.5*[(log(x) - A)/B]^2}

Normal: mean A, standard deviation B, B > 0

        f(x) = {1/[sqrt(2*pi)*B]}*exp{-0.5*[(x - A)/B]^2}

Uniform: real parameters A and B, B > A

        f(x) = 1/(B - A)

Weibull: parameters A and B, A > 0, B > 0, x > 0

        f(x) = (A/B)*[x^(A - 1)]*exp[-(x^A)/B])

F: M (numerator), N (denominator) deg. of freedom, x > 0

    f(x)=[(M/N)^(M/2)]*[x^(M/2 - 1)]/[beta(M/2,N/2)*{[1+(M/N)*x]^[(M+N)/2]}]

t: N degrees of freedom

    f(x)=gamma[(N+1)/2]/[sqrt(N*pi)*gamma(N/2)*{[1+(x^2)/N]^[(N+1)/2]}]

Binomial: parameters N and p, N > 1, 0 =< p =< 1

        f(x) = N!*(p^x)*[(1 - p)^(N - x)]/{x!*(N - x)!}

Poisson: mean T, T > 0

        f(x) = (T^x)*exp(-T)/x!)

Uniform: integer parameters M and N, N > M

        f(x) = 1/(N - M + 1)

Random Walks

In a random walk a particle starts at a position, say (a,b,c), and moves to a sequence of positions, say (x(t),y(t),z(t)), where the increments are random variables from a probability distribution, and there may be additional complexities, like a random cycle time or else absorbing or reflecting barriers.

The classical unrestricted random walk consists of steps of a fixed length at constant step times, so it corresponds to a walk on an integer grid with steps of +1 with probablity p, and steps of -1 with probability q = 1 - p.

- Choose the number of variables (dimension), the number of steps, the starting position and the density functions. Note that there is an independent pdf for each dimension.
- After each simulation you can either see a table of values, a plot of the walk, or write a file. However, note that every output generates a completely new random walk.
- Files generated can be referenced in a library file so that program SIMPLOT can overlay a set of many random walks.

Random matrices

You select a range [A,B] where B is greater than or equal to A for the column mean vector, and a range [C,D] where D is greater than or equal to C (and C is greater than zero) for the column standard deviation vector. Then, for chosen n and m, a n by m random matrix X = x(i,j) can be generated, where the column means (mu(j)) are uniformally distributed on [A,B] and the column standard deviations (sigma(j)) are uniformally distributed on [C,D] and the columns are normally distributed. That is, for column j = 1, 2, ..., m, x(i,j) is distributed as N(mu(j), sigma(j)^2), for row i = 1, 2, ..., n. The 1-way ANOVA null hypothesis is that the mu(j) and sigma(j) are all equal.

Permutations

You can input a vector and this option will generate a random permutation or you can request the program to generate random n by n Latin Squares to use in a Latin Square ANOVA design. In both cases a uniform distribution is employed.

Testing the U(0,1) generator

As everything hinges on the robustness of the U(0,1) generator you can test that this generates sequences that populate the range (0,1) evenly with minimal sequence deficiencies using various tests as follows.

- Runs up (or down) test
- Bar chart visualisation
- Chi-squared test
- Kolmogorov-Smirnov test

The current SIMFIT U(0,1) generator has been developed from RANDGEN, an implementation of the Marsaglia-Zaman subtract-with-borrow algorithm by Chandler and Northrop, which has a period of 2^{1376}.