DEFINITION MODULE RandNormal;
(*******************************************************************
Module RandNormal (Version 1.0)
Copyright (c) 1987-2006 by Andreas Fischlin and ETH Zurich.
Purpose Computation of normally distributed variates.
Remarks This implementation allows to be completely independent
from any particular random number generator (see InstallU).
NOTE: The module won't crash if InstallU is never called,
but it will not produce correct results!
References:
Bell, J.R. 1968. Normal random deviates. Algorithm
334. Colected Algorithms from CACM (Communications
of the Association for Computing Machinery): 334-P 1-R1.
Box, G. & Muller, M. 1958. A note on the generation of
normal deviates. Ann. Math. Stat. 28: 610.
Von Neumann, J. 1959. Various techniques used in
connection with random digits. In: Nat. Bur.
Standards Appl. Math. Ser. 12, US GTovt. Printing Off.,
Washington, D.C., p36.
Programming
o Design
Andreas Fischlin 17/12/1987
o Implementation
Andreas Fischlin 17/12/1987
ETH Zurich
Systems Ecology
CHN E 35.1
Universitaetstrasse 16
8092 Zurich
SWITZERLAND
URLs:
<mailto:RAMSES@env.ethz.ch>
<http://www.sysecol.ethz.ch>
<http://www.sysecol.ethz.ch/SimSoftware/RAMSES>
Last revision of definition: 22/03/1993 AF
******************************************************************)
TYPE
URandGen = PROCEDURE(): REAL;
PROCEDURE InstallU(U: URandGen);
(*
Installs procedure U which returns variates
from a random variable uniformally distributed within
interval [0..1). (NOTE: Always call
this procedure before calling N or Np).
*)
PROCEDURE N(): REAL;
PROCEDURE Np(mu,stdDev: REAL): REAL;
(*
Return a variate from a normally distributed random variable
with mean mu and the standard deviation stdDev. For N these
parameters have to be set by procedure SetPars, where the
default values for mu respectively stdDev are 0 resp. 1.0.
The variates are computed by the method Box and Muller
and the Von Neumann rejection technique.
Implementation note: Crashing of N() or Np in case where U()
returns zero is prevented by calling U() again; however, if
zero is an absorbing state for U() this would lead to an
infinite loop within N() resp. Np(); hence, the implementation
counts the occurrences of U() returning zero and halts program
execution after 50000 occurrences.
*)
PROCEDURE SetPars(mu,stdDev: REAL);
PROCEDURE GetPars(VAR mu,stdDev: REAL);
(*
Set or get the current parameters mu (mean) and the
stdDev (standard deviation = SQRT(variance)) for
the normally distributed random variable for which
procedure N returns variates.
*)
PROCEDURE ResetN;
(*
The here adopted method (Box and Muller and the Von Neumann
rejection) computes at each second call of N resp. Np two
values. Inbetween the already computed and not yet used value
is simply returned without any further calculations. In order
to produce completely defined results, for instance after
setting a new seed value in the basic pseudo-random sequence
used by U, call this procedure. Only this will fully reset the
internal mode of this module and put it to a state where it
always produces the same pseudo random sequence of normally
distributed variates.
*)
END RandNormal.