SED navigation bar go to SED home page go to Dataplot home page go to NIST home page SED Home Page SED Staff SED Projects SED Products and Publications Search Dataplot Pages
Dataplot Vol 2 Vol 1

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

    LET X = NORMA RANDOM NUMBERS FOR I = 3 2 21

you will get something like

    0.00000
    0.00000
    0.75750
    0.00000
    -0.90033
    0.00000
    2.52521
    0.00000
    0.41734
    0.00000
    -1.13290
    0.00000
    0.58353
    0.00000
    0.47807
    0.00000
    -0.64190
    0.00000
    -1.09908
    0.00000
    1.86310

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

where <generator> is one of the following

FIBONACCI - 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) GAMMA
Generalized Extreme Value GENERALIZED EXTREME VALUE GAMMA
Pareto PARETO GAMMA
Inverse Gaussian INVERSE GAUSSIAN GAMMA
Reverse Inverse Gaussian REVERSE INVERSE GAUSSIAN GAMMA
Generalized Inverse Gaussian GENERALIZED INVERSE GAUSSIAN CHI, LAMBDA and THETA
Fatigue Life FATIGUE LIFE GAMMA
Wald WALD GAMMA
Generalized Pareto GENERALIZED PARETO GAMMA
Geometric Extreme Exponential GEOMETRIC EXTREME EXPONENTIAL GAMMA
Generalized Logistic GENERALIZED LOGISTIC GAMMA
Generalized Half Logistic GENERALIZED HALF LOGISTIC GAMMA
Pearson Type 3 PEARSON TYPE 3 GAMMA
Power POWER C
Reflected Power REFLECTED POWER C
Asymmetric Double Exponential ASYMMETRIC DOUBLE EXPONENTIAL (or ASYMMETRIC LAPLACE) K
Generalized Asymmetric Double Exponential GENERALIZED ASYMMETRIC DOUBLE EXPONENTIAL (or GENERALIZED ASYMMETRIC LAPLACE) K
Classical Matching MATCHING K
Folded Normal FOLDED NORMAL MU and SD
Normal Mixture NORMAL MIXTURE MU1, SD1, MU2 and SD2
Non-Central Chi-Square NON CENTRAL CHI SQUARE NU and LAMBDA
Non-Central t NON CENTRAL CT NU and LAMBDA
Skew t SKEW CT NU and LAMBDA
Log-Skew t LOG SKEW CT NU, LAMBDA and SD
Doubly Non-Central t DOUBLY NON CENTRAL T NU, LAMBDA1 and LAMBDA2
Non-Central F NON CENTRAL F NU1, NU2 and LAMBDA
Non-Central Beta NON CENTRAL BETA NU1, NU2 and LAMBDA
Doubly Non-Central F DOUBLY NON CENTRAL F NU1, NU2, LANBDA1 and LAMBDA2
Generalized Tukey-Lambda GENERALIZED TUKEY LAMBDA LAMBDA3 and LAMBDA4
Power POWER P
Geometric GEOMETRIC P
Yule YULE P
Binomial BINOMIAL P and N
Negative Binomial NEGATIVE BINOMIAL P and K
Hypergeometric HYPERGEOMETRIC L, K, N and M
Log-Logistic LOG LOGISTIC DELTA
Log Double Exponential LOG DOUBLE EXPONENTIAL ALPHA
Error ERROR ALPHA
Zipf ZIPF ALPHA
Logistic-Exponential LOGISTIC EXPONENTIAL BETA
Bradford BRADFORD BETA
Topp and Leone TOP AND LEONE BETA
Muth MUTH BETA
Reciprocal RECIPROCAL B
Gompertz GOMPERTZ C and B
Logarithmic Series LOGARITHMIC SERIES THETA
Generalized Logarithmic Series GENERALIZED LOGARITHMIC SERIES THETA and BETA
Geeta GEETA THETA and BETA
Generalized Negative Binomial GENERALIZED NEGATIVE BINOMIAL THETA, BETA and M
Truncated Generalized Negative Binomial TRUNCATED GENERALIZED NEGATIVE BINOMIAL THETA, BETA, M and N
Exponentiated Weibull Exponentiated Weibull GAMMA and THETA
Two-Sided Power TWO SIDED POWER THETA and N
G G G
G and H GH G and H
Gompertz-Makeham GOMPERTZ MAKEHAM XI, LAMBDA and THETA
Bi-Weibull BIWEIBULL SCALE1, GAMMA1, LOC2,SCALE2 and GAMMA2
Trapezoid TRAPEZOID A, B, C and D
Generalized Trapezoid GENERALIZED TRAPEZOID A, B, C, D, NU1, NU3 and ALPHA
Waring WARING A and C
Truncated Pareto TRUNCATED PARETO GAMMA and A
Mielke Beta-Kappa MIELKE BETA KAPPA K and THETA
Kappa KAPPA K and H
Burr Type 2 BURR TYPE 2 R
Burr Type 3 BURR TYPE 3 R and K
Burr Type 4 BURR TYPE 4 R and C
Burr Type 5 BURR TYPE 5 R and K
Burr Type 6 BURR TYPE 6 R and K
Burr Type 7 BURR TYPE 7 R
Burr Type 8 BURR TYPE 8 R
Burr Type 9 BURR TYPE 9 R and K
Burr Type 10 BURR TYPE 10 R
Burr Type 11 BURR TYPE 11 R
Burr Type 12 BURR TYPE 12 C and K
Doubly Pareto Uniform DOUBLY PARETO UNIFORM M, N, ALPHA and BETA
Asymmetric Log-Laplace ASYMMETRIC LOG LAPLACE ALPHA and BETA
Uneven Two-Sided Power UNEVEN TWO SIDED POWER A, B, D, NU1, NU3 and ALPHA
Slope SLOPE ALPHA
Two-Sided Slope TWO SIDED SLOPE ALPHA and THETA
Ogive OGIVE N
Two-Sided Ogive TWO SIDED OGIVE N and THETA
Wakeby WAKEBY BETA, GAMMA and DELTA
Quasi Binomial Type 1 QUASI BINOMIAL TYPE I P and PHI
Consul CONSUL THETA and M
Discrete Weibull DISCRETE WEIBULL Q and BETA
Lost Games LOST GAMES P and R
Generalized Lost Games GENERALIZED LOST GAMES P, J and A
Bessel I BESSEL I S1SQ, S2SQ and NU



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.