Dataplot Reference Manual
Volume 2: LET Subcommands and Library Functions
Chapter 5: Random Numbers
Introduction
The generation of random numbers is performed via subcommands under the
LET command, as in
LET X = UNIFORM RANDOM NUMBERS FOR I = 1 1 25
LET Y = NORMAL RUNDOM NUMBERS FOR I = 1 1 100
LET GAMMA = 2.5
LET Z = WEIBULL RUNDOM NUMBERS FOR I = 1 1 100
In the above, the FOR sequence has three numbers. The first defines
the start row for the output variable, the second defines the row
increment and the third defines the last row. The start row and
row increment are usually set to 1. Also, in the FOR clause, you
must use I as the dummy index (i.e., FOR I). If you use another name,
the results may be unpredictable. If you enter
That is, the output values start in row 3 and after that every other
row is skipped. Any skipped rows will be set to 0 for a new variable
and will keep their current value for a previously existing variable.
The output from the random number generation is always a variable
(never a parameter or function). Random numbers can be generated from
a variety of distributions. Some distributions represent a family of
distributions. In this case, one or more parameters need to be
specified (via the LET command) before generating the random numbers.
Setting the Seed
The SEED command is used to specify the seed for the random number
generator. For example,
SEED 32109
LET Y = UNIFORM RANDOM NUMBERS FOR I = 1 1 1000
The purpose of the seed is to allow a specific set of random numbers
to be replicated. That is, to obtain the same random numbers use the
same seed value.
Available Uniform Random Number Generators
Random numbers for all distributions are ultimately based on generating
uniform random numbers. Dataplot supports a number of uniform random
number generators. The desired uniform random number generator is
specified with the command
this is is a Fibonacci generator as defined by George Marsaglia
in “Comments on the Perfect Random Number Generator” (unpublished
notes from Washington State University). Dataplot uses an
implementation of this algorithm from James Blue and David
Kahaner. For this algorithm, the seed should have a minimum
value of 305 and be an odd integer. Values less than 305 will
use 305 and even integers will be equivalent to the nearest odd
integer.
LINEAR CONGRUENTIAL
-
this implements a linear congruential generator. This
generator is not recommended for routine use. It is
included to allow for comparisons to other generators.
It uses the RUNIF routine of Arthur Fullerton. This generator
does not utilize a seed.
MULTIPLICATIVE CONGRUENTIAL
-
this implements the SUNIF multiplicative congruential generator
given in ACM algorithm 599 (ACM-Trans. Math. Software, Vol.9,
No. 2, June, 1983, pp. 255-257). This is considered a better
generator than the linear congruential generator.
FIBONACCI CONGRUENTIAL
-
this is a combination of a Fibonacci and multiplicative
congruential generator. The algorithm is from Kahaner and
Marsagalia and given in Kahanar, Moler and Nash, "Numerical
Methods and Software".
LUXURY
-
this implements the RANLUX generator of F. James. It is a
modified version of the Marsaglia and Zaman rcarry method..
GENZ
-
this is a generator written by Alan Genz. It is based on
Pierre L'Ecuyer (1996), "Combined Multiple Recursive Random
Number Generator," Operations Research 44, pp. 816-822.
AS183
-
this is the Applied Statistics Aalgorithm 183 generator.
GFSR
-
this is the generalized feedback shift register of Lewis and
Payne as implemented by Monohan. It is documented in
T. G. Lewis and W. H. Payne (1973), "Generalize Feedback Shift
Register Pseudorandom Numbers", Journal of the ACM, Vol. 20,
pp. 456-468.
FUSHIMI
-
this is the Fushimi-Tezuka generalized feedback shift
register generator. It is documented in M. Fushimi and S.
Tezuka (1983), "The J-Distribution of Generalized Feedback
Shift Register Psuedorandom Numbers," Ccommunications of
the ACM, Vol. 26, No. 7, pp. 516-523.
MERSENNE TWISTER
-
This generator is currently not available.
Available Distributions
Random number generation is available for the following distributions.
Random numbers are generated for the standard form of the
distribution (i.e., location parameter = 0, scale parameter = 1).
For non-standard forms of the distribution, you can do something like
the following
LET LOC = 10
LET SCALE = 5
LET Y = NORMAL RANDOM NUMBERS FOR I = 1 1 100
LET Y = LOC + SCALE*Y
with LOC and SCALE denoting the location and scale parameters,
respectively. Note that this applies to all distributions, not
just the normal distribution (sometimes a parameter will be called
a scale parameter when it is in fact a shape parameter).
Distribution
Name on the LET command
Name of Required Shape Parameter(s)
Normal
NORMAL
None
Uniform
UNIFORM
None
Logistic
LOGISTIC
None
Double Exponential
DOUBLE EXPONENTIAL (or LAPLACE)
None
Cauchy
CAUCHY
None
Semi-Circular
SEMICIRCULAR
None
Triangular
TRIANGULAR
None
Half-Normal
HALF NORMAL (or HALFNORMAL)
None
Exponential
EXPONENTIAL
None
Gumbel
EXTREME VALUE TYPE I (or GUMBEL)
None
Half-Cauchy
HALF CAUCHY
None
Cosine
COSINE
None
Anglit
ANGLIT
None
Arcsine
ARCSIN
None
Hyperbolic Secant
HYPERBOLIC SECANT
None
Half-Logistic
HALF LOGISTIC
None
Slash
SLASH
None
Rayleigh
RAYLEIGH
None
Maxwell
MAXWELL
None
Landau
LANDAU
None
Lognormal
LOGNORMAL
SIGMA
Discrete Uniform
DISCRETE UNIFORM
N
Leads in Coin Tossing (or Discrete Arcsine)
LEADS IN COIN TOSSING
N
t
T
NU
Chi-Square
CHI SQUARE (or CHISQUARE)
NU
Folded t
FOLDED T
NU
Tukey-Lambda
TUKEY LAMBDA
LAMBDA
Poisson
POISSON
LAMBDA
Skew Normal
SKEW NORMAL
LAMBDA
Log-Skew Normal
LOG SKEW NORMAL
LAMBDA and SD
Skewed Double Exponential
SKEWED DOUBLE EXPONENTIAL
LAMBDA
Borel-Tanner
BOREL TANNER
LAMBDA
Lagrange-Poisson
LAGRANGE POISSON
LAMBDA and THETA
F
F
NU1 and NU2
Beta
BETA
ALPHA and BETA
Kumaraswamy
KUMARASWAMY
ALPHA and BETA
Power Law
POWER LAW
ALPHA and BETA
Alpha
ALPHA
ALPHA and BETA
Power Exponential
POWER EXPONENTIAL
ALPHA and BETA
Inverted Beta
INVERTED BETA
ALPHA and BETA
Log-Beta
LOG BETA
ALPHA, BETA, C and D
Beta-Negative Binomial
BETA NEGATIVE BINOMIAL
ALPHA, BETA and K
Generalized Topp and Leone
GENERALIZED TOPP AND LEONE
ALPHA and BETA
Reflected Generalized Topp and Leone
REFLECTED GENERALIZED TOPP AND LEONE
ALPHA and BETA
Hermite
HERMITE
ALPHA and BETA
Beta-Geometric
BETA GEOMETRIC
ALPHA and BETA
Katz
KATZ EXPONENTIAL
ALPHA and BETA
Brittle Fracture
BRITTLE FRACTURE
ALPHA and BETA
Exponential Power
EXPONENTIAL POWER
BETA
Alpha
ALPHA
ALPHA
McLeish
MCLEISH
ALPHA
Generalized McLeish
GENERALIZED MCLEISH
ALPHA and A
Zeta
ZETA
ALPHA
Zipf
ZIPF
ALPHA and N
Gamma
GAMMA
GAMMA
Double Gamma
DOUBLE GAMMA
GAMMA
Inverted Gamma
INVERTED GAMMA
GAMMA
Log Gamma
LOG GAMMA
GAMMA
Weibull
WEIBULL
GAMMA
Double Weibull
DOUBLE WEIBULL
GAMMA
Extreme Value Type 2
EXTREME VALUE TYPE II (or EXTREME VALUE TYPE 2 or
FRECHET)
Several distributions generate a matrix, as oppossed to a vector,
of random numbers.
Multivariate normal distribution:
LET MU = DATA <list of p means>
READ MATRIX SIGMA
<pxp set of values that defines the covariance matrix>
END OF DATA
LET N = <value>
LET M = MULTIVARIATE NORMAL RANDOM NUMBERS MU SIGMA N
Note that M will be an NxP matrix. N is the number of rows
generated for each component and their are P components to
the multivariate normal. SIGMA is the pxp variance-covariance
matrix of the multivariate normal. SIGMA will be checked to
ensure that it is a positive definite matrix. MU is a vector
specifying the means of the p components.
Multivariate t distribution:
LET MU = DATA <list of p means>
LET NU = DATA <list of p degrees of freedom>
READ MATRIX SIGMA
<pxp set of values that defines the covariance matrix>
END OF DATA
LET N = <value>
LET M = MULTIVARIATE T RANDOM NUMBERS MU SIGMA NU N
The variables are the same as for the multivariate normal random
numbers with the exception that there is an additional vector,
NU, that specifies the degrees of freedom for the p components.
Uniform distribution:
LET U = INDEPENDENT UNIFORM RANDOM NUMBERSS LOWL UPPL NP
LET U = MULTIVARIATE UNIFORM RANDOM NUMBERSS SIGMA N
The first syntax generates independent uniform random numbers
with LOWL and UPPL denoting vectors that contain the lower and
upper limits for the uniform distributions, respectively. The
scalar NP denotes the number of rows to generate.
The second syntax generates correlated uniform random numbers.
The matrix SIGMA is the variance-covariance matrix of a
multivariate uniform distribution and N denotes the number of
rows to generate.
Multinomial distribution:
LET P = DATA <list of probabilities that sum to 1>
LET N = <value>
LET NEVENTS = <value>
LET M = MULTINOMIAL RANDOM NUMBERS P N NEVENTS
The P variable defines the probabilities for each of the
outcomes, N defines the number of trials, and NEVENTS
defines the number of multinomial experiments to simulate.
The returned M will be a matrix with NEVENTS rows and
the number of columns equal to the number of rows in P.
Dirichlet distribution:
LET ALPHA = DATA <list of shape parameters>
LET N = <value>
LET D = DIRICHLET RANDOM NUMBERS ALPHA N
The ALPHA variable contains the shape parameters of the
Dirichlet distribution and N denotes the number of rows to
generate.
Wishart distribution:
LET P = DATA <list of probabilities that sum to 1>
LET N = <value>
LET NEVENTS = <value>
LET W = WISHART RANDOM NUMBERS MU SIGMA N
Note that W will be a PxP matrix. N is a scalar that specifies
the sample size. SIGMA is the pxp variance-covariance
matrix of the multivariate normal. SIGMA will be checked to
ensure that it is a positive definite matrix. MU is a vector
specifying the means of the p components.
Program Example 1
multiplot 2 2
multiplot corner coordinates 5 5 95 95
multiplot scale factor 2
title case asis
let y = normal random numbers for i = 1 1 100
title Histogram of 1000 Normal Random Numbers
histogram y
title Normal Probability Plot of 1000 Normal Random Numbers
normal probability plot y
let ynew = 50 + 20*y
title Location: 50, Scale: 20
histogram ynew
let z = laplace random numbers for i = 1 1 100
title Normal Probability Plot of Laplace Random Numbers
normal probability plot z
end of multiplot
Program Example 2
multiplot 2 2
multiplot corner coordinates 5 5 95 95
multiplot scale factor 2
title case asis
let y1 = uniform random numbers for i = 1 1 100
let y2 = exponential random numbers for i = 1 1 100
let gamma = 5.2
let y3 = weibull random numbers for i = 1 1 100
let gamma = 2.7
let y4 = frechet random numbers for i = 1 1 100
.
title Uniform Random Numbers
histogram y1
title Exponential Random Numbers
histogram y2
title Weibull Random Numbers (Gamma = 5.2)
histogram y3
title Frechet Random Numbers (Gamma = 2.7)
histogram y4
end of multiplot
Date created: 06/03/2024
Last updated: 06/03/2024
Please email comments on this WWW page to
alan.heckert@nist.gov.