Generates random variables with a binomial distribution. The general syntax for its use is
y = randbin(N,p)
where N
is a vector representing the number of Bernoulli
trials, and p
is the success probability associated with each
trial.
A Binomial random variable describes the number of successful
outcomes from N
Bernoulli trials, with the probability of
success in each trial being p
. The probability distribution
is
Here we generate 10
binomial random variables, corresponding
to N=100
trials, each with probability p=0.1
, using
both randbin
and then again using rand
(to simulate the trials):
--> randbin(100,.1*ones(1,10)) ans = <uint32> - size: [1 10] Columns 1 to 5 9 9 10 8 9 Columns 6 to 10 7 10 13 9 9 --> sum(rand(100,10)<0.1) ans = <int32> - size: [1 10] Columns 1 to 5 9 11 6 10 9 Columns 6 to 10 6 11 16 9 7