binornd

Binomial random numbers

Syntax

R = binornd(N,P)
R = binornd(N,P,m,n,...)
R = binornd(N,P,[m,n,...])

Description

R = binornd(N,P) generates random numbers from the binomial distribution with parameters specified by the number of trials, N, and probability of success for each trial, P. N and P can be vectors, matrices, or multidimensional arrays that have the same size, which is also the size of R. A scalar input for N or P is expanded to a constant array with the same dimensions as the other input.

R = binornd(N,P,m,n,...) or R = binornd(N,P,[m,n,...]) generates an m-by-n-by-... array containing random numbers from the binomial distribution with parameters N and P. N and P can each be scalars or arrays of the same size as R.

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

More About

expand all

Algorithms

The binornd function uses the direct method using the definition of the binomial distribution as a sum of Bernoulli random variables.

Was this topic helpful?