| Statistics Toolbox | Search  Help Desk |
| binornd | Examples |
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 binomial random numbers with parameters N and P. The size of R is the common size of N and P if both are matrices . If either parameter is a scalar, the size of R is the size of the other. R = binornd(N,P,mm) generates binomial random numbers with parameters N and P. mm is a 1-by-2 vector that contains the row and column dimensions of R. R = binornd(N,p,mm,nn) generates binomial random numbers with parameters N and P. The scalars mm and nn are the row and column dimensions of R.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