A Binomial
(n,p) random variable
X can be represented as the sum of
n independent Bernoulli random variables for which probability of assuming a
1 is
p and the probability of assuming a
0 is
1  p.
X then takes on the values
0,...,n with the point probability distribution
f(i) =  C^{n}_{i} p^{ i} (1  p)^{ ni}  for i = 0,...,n  0  elsewhere 


where
C^{n}_{i} is the combination of
n things taken
i at a time.
 int Binomial_Random_Variate( int n, double p )
This function returns X where X is the Binomial(n,p) random variate described above.
C source code is available for this routine: