Accelerating the pace of engineering and science

# Documentation Center

• Trial Software
• Product Updates

# random

Random numbers

## Syntax

Y = random(name,A)
Y = random(name,A,B)
Y = random(name,A,B,C)
Y = random(name,A,m,n,...)
Y = random(name,A,[m,n,...])
Y = random(name,A,B,m,n,...)
Y = random(name,A,B,[m,n,...])
Y = random(name,A,B,C,m,n,...)
Y = random(name,A,B,C,[m,n,...])

## Description

Y = random(name,A) where name is the name of a distribution that takes a single parameter, returns random numbers Y from the one-parameter family of distributions specified by name. Parameter values for the distribution are given in A.

Y is the same size as A.

Y = random(name,A,B) returns random numbers Y from a two-parameter family of distributions. Parameter values for the distribution are given in A and B.

If A and B are arrays, they must be the same size. If either A or B are scalars, they are expanded to constant matrices of the same size.

Y = random(name,A,B,C) returns random numbers Y from a three-parameter family of distributions. Parameter values for the distribution are given in A, B, and C.

If A, B, and C are arrays, they must be the same size. If any of A, B, or C are scalars, they are expanded to constant matrices of the same size.

Y = random(name,A,m,n,...) or Y = random(name,A,[m,n,...]) returns an m-by-n-by... matrix of random numbers.

Similarly, Y = random(name,A,B,m,n,...) or Y = random(name,A,B,[m,n,...]) returns an m-by-n-by... matrix of random numbers for distributions that require two parameters. Y = random(name,A,B,C,m,n,...) or Y = random(name,A,B,C,[m,n,...]) returns an m-by-n-by... matrix of random numbers for distributions that require three parameters.

If any of A, B, or C are arrays, then the specified dimensions must match the common dimensions of A, B, and C after any necessary scalar expansion.

The following table denotes the acceptable strings for name, as well as the parameters for that distribution:

nameDistributionInput Parameter AInput Parameter BInput Parameter C
'beta' or 'Beta'Beta Distributionab
'bino' or 'Binomial'Binomial Distributionn: number of trialsp: probability of success for each trial
'birnbaumsaunders'Birnbaum-Saunders Distributionβγ
'burr' or 'Burr'Burr Type XII Distributionα: scale parameterc: shape parameterk: shape parameter
'chi2' or 'Chisquare'Chi-Square Distributionν: degrees of freedom
'exp' or 'Exponential'Exponential Distributionμ: mean
'ev' or 'Extreme Value'Extreme Value Distributionμ: location parameterσ: scale parameter
'f' or 'F'F Distributionν1: numerator degrees of freedomν2: denominator degrees of freedom
'gam' or 'Gamma'Gamma Distributiona: shape parameterb: scale parameter
'gev' or 'Generalized Extreme Value'Generalized Extreme Value Distributionk: shape parameterσ: scale parameterμ: location parameter
'gp' or 'Generalized Pareto'Generalized Pareto Distributionk: tail index (shape) parameterσ: scale parameterμ: threshold (location) parameter
'geo' or 'Geometric'Geometric Distributionp: probability parameter
'hyge' or 'Hypergeometric'Hypergeometric DistributionM: size of the populationK: number of items with the desired characteristic in the populationn: number of samples drawn
'inversegaussian'Inverse Gaussian Distributionμλ
'logistic'Logistic Distributionμσ
'loglogistic'Loglogistic Distributionμσ
'logn' or 'Lognormal'Lognormal Distributionμσ
'nakagami'Nakagami Distributionμω
'nbin' or 'Negative Binomial'Negative Binomial Distributionr: number of successesp: probability of success in a single trial
'ncf' or 'Noncentral F'Noncentral F Distributionν1: numerator degrees of freedomν2: denominator degrees of freedomδ: noncentrality parameter
'nct' or 'Noncentral t'Noncentral t Distributionν: degrees of freedomδ: noncentrality parameter
'ncx2' or 'Noncentral Chi-square'Noncentral Chi-Square Distributionν: degrees of freedomδ: noncentrality parameter
'norm' or 'Normal'Normal Distributionμ: mean σ: standard deviation
'poiss' or 'Poisson'Poisson Distributionλ: mean
'rayl' or 'Rayleigh'Rayleigh Distributionb: scale parameter
'rician'Rician Distributions: noncentrality parameterσ: scale parameter
't' or 'T'Student's t Distributionν: degrees of freedom
'tlocationscale't Location-Scale Distributionμ: location parameterσ: scale parameterν: shape parameter
'unif' or 'Uniform'Uniform Distribution (Continuous)a: lower endpoint (minimum)b: upper endpoint (maximum)
'unid' or 'Discrete Uniform'Uniform Distribution (Discrete)N: maximum observable value
'wbl' or 'Weibull'Weibull Distributiona: scale parameterb: shape parameter

## Examples

Generate a 2-by-4 array of random values from the normal distribution with mean 0 and standard deviation 1:

```x1 = random('Normal',0,1,2,4)
x1 =
1.1650  0.0751  -0.6965  0.0591
0.6268  0.3516  1.6961  1.7971
```

The order of the parameters is the same as for normrnd.

Generate a single random value from Poisson distributions with rate parameters 1, 2, ..., 6, respectively:

```x2 = random('Poisson',1:6,1,6)
x2 =
0   0   1   2   5   7```

## See Also

Was this topic helpful?