Random numbers from binomial distribution
generates random numbers from the binomial distribution specified by the number of trials
r
= binornd(n
,p
)n
and the probability of success for each trial
p
.
n
and p
can be vectors, matrices, or
multidimensional arrays of the same size. Alternatively, one or more arguments can be
scalars. The binornd
function expands scalar inputs to constant arrays
with the same dimensions as the other inputs. The function returns a vector, matrix, or
multidimensional array r
of the same size as n
and
p
.
generates an array of random numbers from the binomial distribution with the scalar
parameters r
= binornd(n
,p
,sz1,...,szN
)n
and p
, where
sz1,...,szN
indicates the size of each dimension.
binornd
is a function specific to binomial distribution.
Statistics and Machine Learning Toolbox™ also offers the generic function random
, which supports various probability distributions. To use
random
, specify the probability distribution name and its
parameters. Alternatively, create a BinomialDistribution
probability distribution object and pass the object as an
input argument. Note that the distribution-specific function
binornd
is faster than the generic function
random
.
To generate random numbers interactively, use randtool
, a user interface for random number generation.