Anda di halaman 1dari 4

2017. 8. 13.

Random numbers - MATLAB random

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.

https://www.mathworks.com/help/stats/random.html?searchHighlight=random&s_tid=doc_srchtitle 1/4
2017. 8. 13. Random numbers - MATLAB random
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:

Input Parameter Input Input Parameter


name Distribution Input Parameter B
A Parameter C D

'beta' or 'Beta' Beta Distribution a b — —

'bino' or Binomial n: number of p: probability of — —


'Binomial' Distribution trials success for each
trial

'birnbaumsaunders' Birnbaum- β γ — —
Saunders
Distribution

'burr' or 'Burr' Burr Type XII α: scale c: shape k: shape —


Distribution parameter parameter parameter

'chi2' or Chi-Square ν: degrees of — — —


'Chisquare' Distribution freedom

'exp' or Exponential μ: mean — — —


'Exponential' Distribution

'ev' or 'Extreme Extreme Value μ: location σ: scale parameter — —


Value' Distribution parameter

'f' or 'F' F Distribution ν1: numerator ν2: denominator — —


degrees of degrees of
freedom freedom

'gam' or 'Gamma' Gamma a: shape b: scale parameter — —


Distribution parameter

'gev' or Generalized k: shape σ: scale parameter μ: location —


'Generalized Extreme Value parameter parameter
Extreme Value' Distribution

'gp' or Generalized Pareto k: tail index σ: scale parameter μ: threshold —


'Generalized Distribution (shape) (location)
Pareto' parameter parameter

'geo' or Geometric p: probability — — —


'Geometric' Distribution parameter

'hn' or 'Half Half-Normal μ: location σ: scale — —


Normal' Distribution

'hyge' or Hypergeometric M: size of the K: number of items n: number of —


'Hypergeometric' Distribution population with the desired samples drawn
characteristic in
the population

'inversegaussian' Inverse Gaussian μ λ — —


Distribution

'logistic' Logistic Distribution μ σ — —

'loglogistic' Loglogistic μ σ — —
Distribution

https://www.mathworks.com/help/stats/random.html?searchHighlight=random&s_tid=doc_srchtitle 2/4
2017. 8. 13. Random numbers - MATLAB random

Input Parameter Input Input Parameter


name Distribution Input Parameter B
A Parameter C D

'logn' or Lognormal μ σ — —
'Lognormal' Distribution

'nakagami' Nakagami μ ω — —
Distribution

'nbin' or 'Negative Negative Binomial r: number of p: probability of — —


Binomial' Distribution successes success in a
single trial

'ncf' or Noncentral F ν1: numerator ν2: denominator δ: noncentrality —


'Noncentral F' Distribution degrees of degrees of parameter
freedom freedom

'nct' or Noncentral t ν: degrees of δ: noncentrality — —


'Noncentral t' Distribution freedom parameter

'ncx2' or Noncentral Chi- ν: degrees of δ: noncentrality — —


'Noncentral Chi- Square Distribution freedom parameter
square'

'norm' or 'Normal' Normal Distribution μ: mean σ: standard — —


deviation

'poiss' or Poisson λ: mean — — —


'Poisson' Distribution

'rayl' or Rayleigh b: scale — — —


'Rayleigh' Distribution parameter

'rician' Rician Distribution s: noncentrality σ: scale parameter — —


parameter

'stable' Stable Distribution α: first shape β: second shape γ: scale δ: location


parameter parameter parameter parameter

't' or 'T' Student's t ν: degrees of — — —


Distribution freedom

'tlocationscale' t Location-Scale μ: location σ: scale parameter ν: shape —


Distribution parameter parameter

'unif' or 'Uniform' Uniform a: lower endpoint b: upper endpoint — —


Distribution (minimum) (maximum)
(Continuous)

'unid' or 'Discrete Uniform N: maximum — — —


Uniform' Distribution observable value
(Discrete)

'wbl' or 'Weibull' Weibull Distribution a: scale b: shape — —


parameter parameter

Examples collapse all

 Generate Random Numbers from a Probability Distribution

Generate a 2-by-4 array of random values from the normal


distribution with mean equal to 0 and standard deviation equal to 1. Try it in MATLAB

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

x1 =

https://www.mathworks.com/help/stats/random.html?searchHighlight=random&s_tid=doc_srchtitle 3/4
2017. 8. 13. Random numbers - MATLAB random

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

Extended Capabilities

C/C++ Code Generation


Generate C and C++ code using MATLAB® Coder™.

See Also
cdf | fitdist | icdf | makedist | mle | pdf

Topics
Working with Probability Distributions

Introduced before R2006a

https://www.mathworks.com/help/stats/random.html?searchHighlight=random&s_tid=doc_srchtitle 4/4

Anda mungkin juga menyukai