```========================================================================= Date: Fri, 21 Feb 2003 10:34:27 -0500 Reply-To: "Chakravarthy, Venky" Sender: "SAS(r) Discussion" From: "Chakravarthy, Venky" Subject: Re: RAND function (was: Using a macro to simulate data) Comments: To: Pete Lund Content-Type: text/plain; charset="iso-8859-1" For folks who do not have V9, but are interested in seeing the documentation it is freely available at the SAS site (after making a one time registration). If you have already registered the link to the RAND function is: http://v9doc.sas.com/cgi-bin/sasdoc/cgigdoc?file=../lrdict.hlp/a001466748.ht m __________________________ Venky Chakravarthy E-mail: swovcc@hotmail.com -----Original Message----- From: Pete Lund [mailto:pete.lund@NWCSR.COM] Sent: Friday, February 21, 2003 10:27 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: RAND function (was: Using a macro to simulate data) Howard (and Ian)- The V9 documentation for RAND is relatively extensive. Here's a cut-and-paste from the on-line help - please note that the formula for each distribution is given in the documentation but most are in graphic form and don't come through in the text-based paste here: Functions and CALL Routines RAND Function ------------------------------------------------------------------------ -------- Generates random numbers from a specified distribution Category: Random Number ------------------------------------------------------------------------ -------- Syntax Arguments Details Reproducing a Random Number Stream Bernoulli Distribution Beta Distribution Binomial Distribution Cauchy Distribution Chi-Square Distribution Erlang Distribution Exponential Distribution F Distribution Gamma Distribution Geometric Distribution Hypergeometric Distribution Lognormal Distribution Negative Binomial Distribution Normal Distribution Poisson Distribution T Distribution Tabled Distribution Triangular Distribution Uniform Distribution Weibull Distribution Examples See Also References ------------------------------------------------------------------------ -------- Syntax RAND ('dist', parm-1, ... ,parm-k) Arguments 'dist' is a character string that identifies the distribution. Valid distributions are as follows: Distribution Argument Bernoulli 'BERNOULLI' Beta 'BETA' Binomial 'BINOMIAL' Cauchy 'CAUCHY' Chi-Square 'CHISQUARE' Erlang 'ERLANG' Exponential 'EXPONENTIAL' F 'F' Gamma 'GAMMA' Geometric 'GEOMETRIC' Hypergeometric 'HYPERGEOMETRIC' Lognormal 'LOGNORMAL' Negative binomial 'NEGBINOMIAL' Normal 'NORMAL'|'GAUSSIAN' Poisson 'POISSON' T 'T' Tabled 'TABLE' Triangular 'TRIANGLE' Uniform 'UNIFORM' Weibull 'WEIBULL' Note: Except for T and F, you can minimally identify any distribution by its first four characters. parm-1, . . . ,parm-k are shape, location, or scale parameters appropriate for the specific distribution. See: Details for complete information about these parameters ------------------------------------------------------------------------ -------- Details The RAND function generates random numbers from various continuous and discrete distributions. Wherever possible, the simplest form of the distribution is used. Reproducing a Random Number Stream If you want to create reproducible streams of random numbers, then use the CALL STREAMINT routine to specify a seed value for random number generation. Do this once per DATA step before any invocation of the RAND function. If you omit the call to the 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 STREAMINT, Creating a Reproducible Stream of Random Numbers. Bernoulli Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('BERNOULLI',p) where x is an observation from the distribution with the following probability density function: Range: x = 0, 1 p is a numeric probability of success. Range: 0 p 1 Beta Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('BETA',a,b) where x is an observation from the distribution with the following probability density function: Range: 0 < x < 1 a is a numeric shape parameter. Range: a > 0 b is a numeric shape parameter. Range: b > 0 Binomial Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('BINOMIAL',p,n) where x is an integer observation from the distribution with the following probability density function: Range: x = 0, 1, ..., n p is a numeric probability of success. Range: 0 p 1 n is an integer parameter that counts the number of independent Bernoulli trials. Range: n = 1, 2, ... Cauchy Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('CAUCHY') where x is an observation from the distribution with the following probability density function: Range: - < x < Chi-Square Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('CHISQUARE',df) where x is an observation from the distribution with the following probability density function: Range: x > 0 df is a numeric degrees of freedom parameter. Range: df > 0 Erlang Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('ERLANG',a) where x is an observation from the distribution with the following probability density function: Range: x > 0 a is an integer numeric shape parameter. Range: a = 1, 2, ... Exponential Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('EXPONENTIAL') where x is an observation from the distribution with the following probability density function: Range: x > 0 F Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('F',ndf, ddf) where x is an observation from the distribution with the following probability density function: Range: x > 0 ndf is a numeric numerator degrees of freedom parameter. Range: ndf > 0 ddf is a numeric denominator degrees of freedom parameter. Range: ddf > 0 Gamma Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('GAMMA',a) where x is an observation from the distribution with the following probability density function: Range: x > 0 a is a numeric shape parameter. Range: a > 0 Geometric Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('GEOMETRIC',p) where x is an integer observation from the distribution with the following probability density function: Range: x = 1, 2, ... p is a numeric probability of success. Range: 0 < p 1 Hypergeometric Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('HYPER',N,R,n) where x is an integer observation from the distribution with the following probability density function: Range: x = max(0, (n - (N - R))), ..., min(n, R) N is an integer population size parameter. Range: N = 1, 2, ... R is an integer number of items in the category of interest. Range: R = 0, 1, ..., N n is an integer sample size parameter. Range: n = 1, 2, ..., N The hypergeometric distribution is a mathematical formalization of an experiment in which you draw n balls from an urn that contains N balls, R of which are red. The hypergeometric distribution is the distribution of the number of red balls in the sample of n. Lognormal Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('LOGNORMAL') where x is an observation from the distribution with the following probability density function: Range: x 0 Negative Binomial Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('NEGBINOMIAL',p,k) where x is an integer observation from the distribution with the following probability density function: Range: x = 0, 1, ... k is an integer number parameter that counts the number of successes. Range: k = 1, 2, ... p is a numeric probability of success. Range: 0 < p 1 The negative binomial distribution is the distribution of the number of failures before k successes occur in sequential independent trials, all with the same probability of success, p. Normal Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('NORMAL',<, , >) where x is an observation from the normal distribution with a mean of and a standard deviation of , that has the following probability density function: Range: - < x < is the mean parameter. Default: 0 is the standard deviation parameter. Default: 1 Range: > 0 Poisson Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('POISSON',m) where x is an integer observation from the distribution with the following probability density function: Range: x = 0, 1, ... m is a numeric mean parameter. Range: m > 0 T Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('T',df) where x is an observation from the distribution with the following probability density function: Range: - < x < df is a numeric degrees of freedom parameter. Range: df > 0 Tabled Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('TABLE',p1,p2, ...) where x is an integer observation from one of the following distributions: If , then x is an observation from this probability density function: If for some index , then x is an observation from this probability density function: p1, p2, ... 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. The tabled distribution takes on the values 1, 2, ..., n with specified probabilities. Note: By using the FORMAT statement, you can map the set {1, 2, ..., n} to any set of n or fewer elements. Triangular Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('TRIANGLE',h) where x is an observation from the distribution with the following probability density function: where 0 h 1. Range: 0 x 1 Note: The distribution can be easily shifted and scaled. h is the horizontal location of the peak of the triangle. Range: 0 h 1 Uniform Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('UNIFORM') where x is an observation from the distribution with the following probability density function: Range: 0 < x < 1 The uniform random number generator that the RAND function uses is the Mersenne-Twister (Matsumoto and Nishimura 1998). This generator has a period of and 623-dimensional equidistribution up to 32-bit accuracy. This algorithm underlies the generators for the other available distributions in the RAND function. Weibull Distribution ------------------------------------------------------------------------ -------- Syntax x = RAND('WEIBULL',a,b) where x is an observation from the distribution with the following probability density function: Range: x 0 a is a numeric shape parameter. Range: a > 0 b is a numeric scale parameter. Range: b > 0 ------------------------------------------------------------------------ -------- Examples SAS Statements Results x=rand('BERN',.75); 0 x=rand('BETA',3,0.1); .99920 x=rand('BINOM',10,0.75); 10 x=rand('CAUCHY'); -1.41525 x=rand('CHISQ',22); 25.8526 x=rand('ERLANG', 7); 7.67039 x=rand('EXPO'); 1.48847 x=rand('F',12,322); 1.99647 x=rand('GAMMA',7.25); 6.59588 x=rand('GEOM',0.02); 43 x=rand('HYPER',10,3,5); 1 x=rand('LOGN'); 0.66522 x=rand('NEGB',5,0.8); 33 x=rand('NORMAL'); 1.03507 x=rand('POISSON',6.1); 6 x=rand('T',4); 2.44646 x=rand('TABLE',.2,.5); 2 x=rand('TRIANGLE',0.7); .63811 x=rand('UNIFORM'); .96234 x=rand('WEIB',0.25,2.1); 6.55778 ------------------------------------------------------------------------ -------- See Also CALL Routine: CALL STREAMINIT Routine ------------------------------------------------------------------------ -------- References Fishman, G. S. 1996. Monte Carlo: Concepts, Algorithms, and Applications.New York: Springer-Verlag. Fushimi, M., and S. Tezuka. 1983. "The k-Distribution of Generalized Feedback Shift Register Pseudorandom Numbers." Communications of the ACM 26: 516-523. Gentle, J. E. 1998. Random Number Generation and Monte Carlo Methods. New York: Springer-Verlag. Lewis, T. G., and W. H. Payne. 1973. "Generalized Feedback Shift Register Pseudorandom Number Algorithm." Journal of the ACM 20: 456-468. Matsumoto, M., and Y. Kurita. 1992. "Twisted GFSR Generators." ACM Transactions on Modeling and Computer Simulation 2: 179-194. Matsumoto, M., and Y. Kurita. 1994. "Twisted GFSR Generators II." ACM Transactions on Modeling and Computer Simulation 4: 254-266. Matsumoto, M., and T. Nishimura. 1998. "Mersenne Twister: A 623-Dimensionally Equidistributed Uniform Pseudo-Random Number Generator." ACM Transactions on Modeling and Computer Simulation 8: 3-30. Ripley, B. D. 1987. Stochastic Simulation. New York: Wiley. Robert, C. P., and G. Casella. 1999. Monte Carlo Statistical Methods. New York: Springer-Verlag. Ross, S. M. 1997. Simulation. San Diego: Academic Press. ```

Back to: Top of message | Previous page | Main SAS-L page