Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

random

Random numbers

Syntax

Y = random(pd)
Y = random(pd,m,n,...)
Y = random(pd,[m,n,...])
Y = random(name,A)
Y = random(name,A,B)
Y = random(name,A,B,C)
Y = random(name,A,B,C,D)
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,...])
Y = random(name,A,B,C,D,m,n,...)
Y = random(name,A,B,C,D,[m,n,...])

Description

Y = random(pd) returns a random number Y from the distribution specified by the probability distribution object pd. You can create a probability distribution object with specified parameter values using makedist, or fit a probability distribution object to sample data using fitdist.

Y = random(pd,m,n,...) or Y = random(pd,[m,n,...]) returns an m-by-n-by... matrix of random numbers from the probability distribution specified by pd.

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,B,C,D) returns random numbers Y from a four-parameter family of distributions. Parameter values for the distribution are given in A, B, C, and D.

If A, B, C, and D are arrays, they must be the same size. If any of A, B, C, or D 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. Y = random(name,A,B,C,D,m,n,...) or Y = random(name,A,B,C,D,[m,n,...]) returns an m-by-n-by... matrix of random numbers for distributions that require four parameters.

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

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

nameDistributionInput Parameter AInput Parameter BInput Parameter CInput Parameter D
'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
'hn' or 'Half Normal'Half-Normal Distributionμ: locationσ: scale
'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
'stable'Stable Distributionα: first shape parameterβ: second shape parameterγ: scale parameterδ: location 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

collapse all

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

x1 = random('Normal',0,1,2,4)
x1 =

    0.5377   -2.2588    0.3188   -0.4336
    1.8339    0.8622   -1.3077    0.3426

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

x2 = random('Poisson',1:6,1,6)
x2 =

     4     2     3     7     4     9

See Also

| | | | |

Introduced before R2006a


Was this topic helpful?