Generates random numbers from a distribution that you specify.

Category: | Random Number |

is a character constant, variable, or expression that identifies the distribution. Valid distributions are as follows:

are shape, location, or scale parameters appropriate for the specific distribution.

See | Details |

The RAND function generates
random numbers from various continuous and discrete distributions.
Wherever possible, the simplest form of the distribution is used.

The RAND function uses
the Mersenne-Twister random number generator (RNG) that was developed
by Matsumoto and Nishimura (1998). The random number generator has
a very long period (2^{19937} – 1)
and very good statistical properties. The period is a Mersenne prime,
which contributes to the naming of the RNG. The algorithm is a twisted
generalized feedback shift register (TGFSR) that explains the latter
part of the name. The TGFSR gives the RNG a very high order of equidistribution
(623-dimensional with 32-bit accuracy), which means that there is
a very small correlation between successive vectors of 623 pseudo-random
numbers.

If you want to create
reproducible streams of random numbers, then use the CALL STREAMINIT
routine to specify a seed value for random number generation. Use
the CALL STREAMINIT routine once per DATA step before any invocation
of the RAND function. If you omit the call to the CALL STREAMINIT
routine (or if you specify a non-positive seed value in the CALL STREAMINIT
routine), then RAND uses a call to the system clock to seed itself.
For more information,
see CALL STREAMINIT Creating a Reproducible Stream of Random Numbers.

The Mersenne-Twister
RNG algorithm has an extremely long period, but this does not imply
that large random samples are devoid of duplicate values. The RAND
function returns at most 2^{32} distinct values.
In a random uniform sample of size 10^{5},
the chance of drawing at least one duplicate is greater than 50%.
The expected number of duplicates in a random uniform sample of size
M is approximately M^{2}/2^{33} when
M is much less than 2^{32}. For example, you should expect about 115 duplicates
in a random uniform sample of size M=10^{6}.
These results are consequences of the famous “birthday matching
problem” in probability theory.

is an integer observation from the distribution with the following probability density function:

$\begin{array}{c}f\left(x\right)=\{\begin{array}{cc}1\hfill & p=0,x=0\hfill \\ \left(\begin{array}{c}n\hfill \\ x\hfill \end{array}\right){p}^{x}{(1-p)}^{n-x}\hfill & 0<p<1,x=0,\mathrm{.}\mathrm{.}\mathrm{.},n\hfill \\ 1\hfill & p=1,x=n\hfill \end{array}\hfill \end{array}$

Range | x = 0, 1, ..., n |

is a numeric probability of success.

Range | 0 ≤ p ≤ 1 |

is an integer parameter that counts the number of independent Bernoulli trials.

Range | n = 1, 2, ... |

is an observation from the distribution with the following probability density function:

$\begin{array}{c}f\left(x\right)=\frac{\Gamma \left(\frac{n+d}{2}\right)}{\Gamma \left(\frac{n}{2}\right)\Gamma \left(\frac{d}{2}\right)}\frac{{n}^{n/2}{d}^{d/2}{x}^{n/2-1}}{{(d+nx)}^{(n+d)/2}}\hfill \end{array}$

Range | x > 0 |

is a numeric numerator degrees of freedom parameter.

Range | n > 0 |

is a numeric denominator degrees of freedom parameter.

Range | d > 0 |

is an integer count that denotes the number of trials that are needed to obtain one success. X is an integer observation from the distribution with the following probability density function:

$\begin{array}{c}f\left(x\right)=\{\begin{array}{cc}{(1-p)}^{x-1}p\phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}\hfill & \phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}0<p<1,x=1,2,\mathrm{.}\mathrm{.}\mathrm{.}\hfill \\ 1\hfill & \phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}p=1,x=1\hfill \end{array}\hfill \end{array}$

Range | x = 1, 2, … |

is a numeric probability of success.

Range | 0 < p ≤ 1 |

is an integer observation from the distribution with the following probability density function:

$\begin{array}{c}f\left(x\right)=\frac{\left(\begin{array}{c}R\hfill \\ x\hfill \end{array}\right)\left(\begin{array}{c}N-R\hfill \\ n-x\hfill \end{array}\right)}{\left(\begin{array}{c}N\hfill \\ n\hfill \end{array}\right)}\hfill \end{array}$

Range | x = max(0, (n – (N – R))), ..., min(n, R) |

is an integer population size parameter.

Range | N = 1, 2, ... |

is an integer number of items in the category of interest.

Range | R = 0, 1, ..., N |

is an integer sample size parameter.

Range | n = 1, 2, ..., N |

x = RAND('LOGNORMAL')

is an observation from the distribution with the following probability density function:

$\begin{array}{c}f\left(x\right)=\frac{{e}^{-{\mathrm{ln}}^{2}\left(x\right)/2}}{x\sqrt[\phantom{\rule{0ex}{0ex}}]{2\phantom{\rule{0.212em}{0ex}}\pi \phantom{\rule{0.212em}{0ex}}}}\hfill \end{array}$

Range | x > 0 |

is an integer observation from the distribution with the following probability density function:

$\begin{array}{c}f\left(x\right)=\{\begin{array}{cc}\left(\begin{array}{c}x+k-1\hfill \\ k-1\hfill \end{array}\right){(1-p)}^{x}{p}^{k}\hfill & \phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}0<p<1,x=0,1,\mathrm{.}\mathrm{.}\mathrm{.}\hfill \\ 1\hfill & \phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}p=1,x=0\hfill \end{array}\hfill \end{array}$

Range | x = 0, 1, ... |

is an integer parameter that is the number of successes. However, non-integer k values are allowed as well.

Range | k = 1, 2, ... |

is a numeric probability of success.

Range | 0 < p ≤ 1 |

is an observation from the normal distribution with a mean of θ and a standard deviation of λ that has the following probability density function:

$\begin{array}{c}f\left(x\right)=\frac{1}{\lambda \sqrt[\phantom{\rule{0ex}{0ex}}]{2\phantom{\rule{0.212em}{0ex}}\pi \phantom{\rule{0.212em}{0ex}}}}\phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}exp(-\frac{{(x-\theta )}^{2}}{2{\lambda}^{2}})\hfill \end{array}$

Range | –∞ < x < ∞ |

is the mean parameter.

Default | 0 |

is the standard deviation parameter.

Default | 1 |

Range | λ > 0 |

is an observation from the distribution with the following probability density function:

$\begin{array}{c}f\left(x\right)=\frac{\Gamma \left(\frac{df+1}{2}\right)}{\sqrt[\phantom{\rule{0ex}{0ex}}]{df\phantom{\rule{0.212em}{0ex}}\pi \phantom{\rule{0.212em}{0ex}}}\Gamma \left(\frac{df}{2}\right)}{(1+\frac{{x}^{2}}{df})}^{-\frac{df+1}{2}}\hfill \end{array}$

Range | –∞ < x < ∞ |

is a numeric degrees of freedom parameter.

Range | df > 0 |

is an integer observation from one of the following distributions:

If
$\underset{i=1}{\overset{n}{\Sigma}}{p}_{i}<1$ , then x is
an observation from this probability density function:

$\begin{array}{c}f\left(i\right)={p}_{i},\phantom{\rule{0.265em}{0ex}}\phantom{\rule{0.265em}{0ex}}i=1,2,\dots ,n\hfill \\ and\hfill \\ f(n+1)=1-\underset{i=1}{\overset{n}{\Sigma}}{p}_{i}\hfill \end{array}$

are numeric probability values.

Range | 0 ≤ p1, p2, ... ≤ 1 |

Restriction | The maximum number of probability parameters depends on your operating environment, but the maximum number of parameters is at least 32,767. |

is an observation from the distribution with the following probability density function:

$\begin{array}{cc}f\left(x\right)=\hfill & \{\begin{array}{cc}\frac{2x}{h}\hfill & \phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}0\le x\le h\hfill \\ \frac{2(1-x)}{1-h}\phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}\hfill & \phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}\phantom{\rule{0.212em}{0ex}}h<x\le 1\hfill \end{array}\hfill \end{array}$

Range | 0 ≤ x ≤ 1 |

Note | The distribution can be easily shifted and scaled. |

is the horizontal location of the peak of the triangle.

Range | 0 ≤ h ≤ 1 |

x = RAND('UNIFORM')

The uniform random number
generator that the RAND function uses is the Mersenne-Twister (Matsumoto
and Nishimura 1998). This generator has a period of
${2}^{19937}-1$ and 623-dimensional equidistribution up to 32-bit
accuracy. This algorithm underlies the generators for the other available
distributions in the RAND function.

1996. Monte Carlo:
Concepts, Algorithms, and Applications. New York, USA: Springer-Verlag.

“The k-Distribution of
Generalized Feedback Shift Register Pseudorandom Numbers.” 1983. Communications
of the ACM 26: 516–523.

1998. Random Number
Generation and Monte Carlo Methods. New
York, USA: Springer-Verlag.

“Generalized Feedback
Shift Register Pseudorandom Number Algorithm.” 1973. Journal
of the ACM 20: 456-468.

“Twisted GFSR Generators.” 1992. ACM Transactions
on Modeling and Computer Simulation 2: 179–194.

“Twisted GFSR Generators
II.” 1994. ACM Transactions on Modeling and Computer Simulation 4: 254–266.

“Mersenne Twister:
A 623–Dimensionally Equidistributed Uniform Pseudo-Random Number
Generator.” 1998. ACM Transactions on Modeling and Computer Simulation 8: 3–30.

1987. Stochastic Simulation. New York, USA: Wiley.

1999. Monte Carlo
Statistical Methods. New York, USA: Springer-Verlag.

1997. Simulation. San Diego, USA: Academic Press.

Copyright © SAS Institute Inc. All rights reserved.