Binomial Distribution - Binomial Distribution - 6.0 English - 68552

AOCL API Guide (68552)

Document_ID
68552
Release_Date
2026-11-10
Version
6.0 English

Generates a vector of random variates from a Binomial distribution with probability, \(f (X)\), defined by:

\[f (X) = \frac{M!P^X (1-P)^{(M-X)}}{X!(M-1)!}, X=0,1,\dotsi,M\]
C Generate 100 values from the Binomial distribution
    INTEGER LSTATE,N
    PARAMETER (LSTATE=16,N=100)
    INTEGER I,INFO,SEED(1),STATE(LSTATE)
    INTEGER M
    DOUBLE PRECISION P

C Set the seed
    SEED(1) = 1234

C Read in the distributional parameters
    READ(5,*) M,P

C Initialize the STATE vector
    CALL DRANDINITIALIZE(1,1,SEED,1,STATE,LSTATE,INFO)

C Generate N variates from the Binomial distribution
    CALL DRANDBINOMIAL(N,M,P,STATE,X,INFO)

C Print the results
    WRITE(6,*) (X(I),I=1,N)