| Statistics Toolbox | ![]() |
Random numbers from the binomial distribution.
Syntax
R = binornd(N,P) R = binornd(N,P,mm) R = binornd(N,P,mm,nn)
Description
R = binornd(N,P)
generates random numbers from the binomial distribution with parameters specified by N and P. Vector or matrix inputs for N and P must have the same size, which is also the size of R. A scalar input for N or P is expanded to a constant matrix with the same dimensions as the other input.
R = binornd(N,P,mm)
generates a matrix of size mm containing random numbers from the binomial distribution with parameters N and P, where mm is a 1-by-2 vector containing the row and column dimensions of R.
R = binornd(N,p,mm,nn)
generates an mm-by-nn matrix containing random numbers from the binomial distribution with parameters N and P.
Algorithm
The binornd function uses the direct method using the definition of the binomial distribution as a sum of Bernoulli random variables.
Examples
n = 10:10:60;
r1 = binornd(n,1./n)
r1 =
2 1 0 1 1 2
r2 = binornd(n,1./n,[1 6])
r2 =
0 1 2 1 3 1
r3 = binornd(n,1./n,1,6)
r3 =
0 1 1 1 0 3
See Also
binocdf, binofit, binoinv, binopdf, binostat, rand, randtool
| binopdf | binostat | ![]() |