Discrete Univariate#

Binomial Distribution#

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)

Geometric Distribution#

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

\[f (X) = P (1 – P )^X , X = 0, 1,\dotsi\]
C Generate 100 values from the Geometric distribution
    INTEGER LSTATE,N
    PARAMETER (LSTATE=16,N=100)
    INTEGER I,INFO,SEED(1),STATE(LSTATE)
    DOUBLE PRECISION P
    INTEGER X(N)

C Set the seed
    SEED(1) = 1234

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

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

C Generate N variates from the Geometric distribution
    CALL DRANDGEOMETRIC(N,P,STATE,X,INFO)

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

Hypergeometric Distribution#

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

\[f (X) = \frac{s!m!(p – s)!(p – m)!}{X!(s – X)!(m – X)!(p – m – s + X)!p!}\]

if X = max(0, m + s – p),…, min(l, m), otherwise f (X) = 0. Here p is the size of the population, (NP), s is the size of the sample taken from the population, (NS) and m is the number of labeled, or specified, items in the population, (M ).

C Generate 100 values from the Hypergeometric distribution
    INTEGER LSTATE,N
    PARAMETER (LSTATE=16,N=100)
    INTEGER I,INFO,SEED(1),STATE(LSTATE)
    INTEGER NP,NS,M
    INTEGER X(N)

C Set the seed
    SEED(1) = 1234

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

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

C Generate N variates from the Hypergeometric distribution
    CALL DRANDHYPERGEOMETRIC(N,NP,NS,M,STATE,X,INFO)

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

Negative Binomial Distribution#

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

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

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 Negative Binomial distribution
    CALL DRANDNEGATIVEBINOMIAL(N,M,P,STATE,X,INFO)

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

Poisson Distribution#

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

\[f(X ) = \frac{\lambda^X e^{-\lambda}}{X!}, \quad X = 0, 1, 2, \ldots\]

where λ is the mean of the distribution, LAMBDA.

C Generate 100 values from the Poisson distribution
    INTEGER LSTATE,N
    PARAMETER (LSTATE=16,N=100)
    INTEGER I,INFO,SEED(1),STATE(LSTATE)
    DOUBLE PRECISION LAMBDA
    INTEGER X(N)

C Set the seed
    SEED(1) = 1234

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

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

C Generate N variates from the Poisson distribution
    CALL DRANDPOISSON(N,LAMBDA,STATE,X,INFO)

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

Discrete Uniform Distribution#

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

\[f (X) = \frac{1}{B - A},X=A,A+1,\dotsi,B\]
C Generate 100 values from the Uniform distribution
    INTEGER LSTATE,N
    PARAMETER (LSTATE=16,N=100)
    INTEGER I,INFO,SEED(1),STATE(LSTATE)
    INTEGER A,B
    INTEGER X(N)

C Set the seed
    SEED(1) = 1234

C Read in the distributional parameters
    READ(5,*) A,B

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

C Generate N variates from the Uniform distribution
    CALL DRANDDISCRETEUNIFORM(N,A,B,STATE,X,INFO)

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

General Discrete Distribution#

Takes a reference vector initialized via one of DRANDBINOMIALREFERENCE, DRANDGEOMETRICREFERENCE, DRANDHYPERGEOMETRICREFERENCE, DRANDNEGATIVEBINOMIALREFERENCE, DRANDPOISSONREFERENCE, and generates a vector of random variates from it.

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
    INTEGER X(N)
    INTEGER LREF
    DOUBLE PRECISION REF(1000)

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 Initialize the reference vector
    LREF = 1000
    CALL DRANDBINOMIALREFERENCE(M,P,REF,LREF,INFO)

C Generate N variates from the Binomial distribution
    CALL DRANDGENERALDISCRETE(N,REF,STATE,X,INFO)

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

Binomial Reference#

Initializes a reference vector for use with DRANDGENERALDISCRETE. Reference vector is for 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
    INTEGER X(N)
    INTEGER LREF
    DOUBLE PRECISION REF(1000)

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 Initialize the reference vector
    LREF = 1000
    CALL DRANDBINOMIALREFERENCE(M,P,REF,LREF,INFO)

C Generate N variates from the Binomial distribution
    CALL DRANDGENERALDISCRETE(N,REF,STATE,X,INFO)

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

Geometric Reference#

Initializes a reference vector for use with DRANDGENERALDISCRETE. Reference vector is for a Geometric distribution with probability, \(f (X)\), defined by:

\[f (X) = P (1 – P )^X , X = 0, 1,\dotsi\]
C Generate 100 values from the Geometric distribution
    INTEGER LSTATE,N
    PARAMETER (LSTATE=16,N=100)
    INTEGER I,INFO,SEED(1),STATE(LSTATE)
    DOUBLE PRECISION P
    INTEGER X(N)
    INTEGER LREF
    DOUBLE PRECISION REF(1000)

C Set the seed
    SEED(1) = 1234

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

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

C Initialize the reference vector
    LREF = 1000
    CALL DRANDGEOMETRICREFERENCE(P,REF,LREF,INFO)

C Generate N variates from the Geometric distribution
    CALL DRANDGENERALDISCRETE(N,REF,STATE,X,INFO)

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

Hypergeometric Reference#

Initializes a reference vector for use with DRANDGENERALDISCRETE. Reference vector is for a Hypergeometric distribution with probability, \(f (X)\), defined by:

\[f(X) = \frac{s! \, m! \, (p-s)! \, (p-m)!} {X! \, (s-X)! \, (m-X)! \, (p-m-s+X)! \, p!}\]

if X = max(0, m + s – p),…, min(l, m), otherwise f (X) = 0. Here p is the size of the population, (NP), s is the size of the sample taken from the population, (NS) and m is the number of labeled, or specified, items in the population, (M ).

C Generate 100 values from the Hypergeometric distribution
    INTEGER LSTATE,N
    PARAMETER (LSTATE=16,N=100)
    INTEGER I,INFO,SEED(1),STATE(LSTATE)
    INTEGER NP, NS,M
    INTEGER X(N)
    INTEGER LREF
    DOUBLE PRECISION REF(1000)

C Set the seed
    SEED(1) = 1234

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

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

C Initialize the reference vector
    LREF = 1000
    CALL DRANDHYPERGEOMETRICREFERENCE(NP, NS,M,REF,LREF,INFO)

C Generate N variates from the Hypergeometric distribution
    CALL DRANDGENERALDISCRETE(N,REF,STATE,X,INFO)

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

Negative Binomial Reference#

Initializes a reference vector for use with DRANDGENERALDISCRETE. Reference vector is for a Negative Binomial distribution with probability \(f (X)\), defined by:

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

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 Initialize the reference vector
    LREF = 1000
    CALL DRANDNEGATIVEBINOMIALREFERENCE(M,P,REF,LREF,INFO)

C Generate N variates from the Hypergeometric distribution
    CALL DRANDGENERALDISCRETE(N,REF,STATE,X,INFO)

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

Poisson Reference#

Initializes a reference vector for use with DRANDGENERALDISCRETE. Reference vector is for a Poisson distribution with probability \(f (X)\) defined by:

\[f (X) = \frac{\lambda^X e^{-\lambda}}{X!},X=0,1,\dotsi\]

where λ is the mean of the distribution, LAMBDA.

C Generate 100 values from the Poisson distribution
    INTEGER LSTATE,N
    PARAMETER (LSTATE=16,N=100)
    INTEGER I,INFO,SEED(1),STATE(LSTATE)
    DOUBLE PRECISION LAMBDA
    INTEGER X(N)
    INTEGER LREF
    DOUBLE PRECISION REF(1000)

C Set the seed
    SEED(1) = 1234

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

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

C Initialize the reference vector
    LREF = 1000
    CALL DRANDPOISSONREFERENCE(LAMBDA,REF,LREF,INFO)

C Generate N variates from the Poisson distribution
    CALL DRANDGENERALDISCRETE(N,REF,STATE,X,INFO)

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