home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
modula2
/
library
/
queuem2
/
xpnlrng.mod
< prev
Wrap
Text File
|
1989-08-31
|
3KB
|
107 lines
(* source: h:\modula\code\random\XpnlRNG.MOD v1.0a revised: 88.06.09
author: G.Greene, AGCS D/429 (NS/TS), 312/681-7783 created: 88.06.09
function:
This is the implementation code for a package which provides a generator
of exponentially-distributed pseudo-random variates. The numbers are in
the form of double-precision reals.
history:
88.06.09 1.0a initial release.
*)
IMPLEMENTATION MODULE XpnlRNG;
FROM MATHLIB IMPORT (*PROC*) Log, Exp;
FROM UnifRNG IMPORT (*PROC*) NonzeroUniformVariate;
(* Return as the function value an exponentially-distributed LongReal value,
with mean (= standard deviation) specified by the parameter.
*)
PROCEDURE ExponentialVariate (
(*in*) Mean: REAL ): LONGREAL;
BEGIN
RETURN LONGREAL ( - Mean ) * Log ( NonzeroUniformVariate ( ) )
END ExponentialVariate;
(* Return as the function value a random variate of the Weibull
distribution with characteristic life and shape parameters specified
by the corresponding function parameters. Both parameters must be
greater than zero (the function returns -1, otherwise). Possible
valid values of the function range from zero to +infinity.
*)
PROCEDURE WeibullVariate (
(*in*) CharacteristicLife: REAL;
(*in*) Shape: REAL ): LONGREAL;
BEGIN
IF ( CharacteristicLife <= 0.0 ) OR ( Shape <= 0.0 ) THEN
RETURN -1.0;
ELSE
RETURN LONGREAL ( CharacteristicLife ) *
(* the following expression is equivalent to:
( -ln ( R ) ** ( 1 / Shape )
... where "**" is the FORTRAN exponential operator
*)
Exp ( Log ( - Log ( NonzeroUniformVariate ( ) ) ) /
LONGREAL ( Shape ) );
END;
END WeibullVariate;
(* [2]
source: h:\modula\code\random\XpnlRNG.MOD v1.0a revised: 88.06.09 *)
(* Return as the function value a random variate of the logistic
distribution, with mean and standard deviation specified by the
corresponding function parameters.
*)
PROCEDURE LogisticVariate (
(*in*) Mean: REAL;
(*in*) StdDev: REAL ): LONGREAL;
CONST
Factor = 0.4189192692; (* = sqrt (3) / pi *)
VAR
UniformVariate: LONGREAL;
BEGIN
UniformVariate := NonzeroUniformVariate ( );
RETURN LONGREAL ( Mean ) + LONGREAL ( StdDev ) * Factor *
Log ( UniformVariate / ( 1.0 - UniformVariate ) )
END LogisticVariate;
(* Return as the function value a variate of the extreme-value distribution.
The mode and scale of the distribution are specified by the corresponding
function parameters.
*)
PROCEDURE ExtremeValueVariate (
(*in*) Mode: REAL;
(*in*) Scale: REAL ): LONGREAL;
BEGIN
RETURN LONGREAL ( Mode ) +
LONGREAL ( Scale ) * Log ( - Log ( NonzeroUniformVariate ( ) ) )
END ExtremeValueVariate;
END XpnlRNG.