RNBIN
Generates pseudorandom numbers from a binomial distribution.
Required Arguments
N — Number of Bernoulli trials. (Input)
P — Probability of success on each trial. (Input)
P must be greater than 0.0 and less than 1.0.
IR — Vector of length NR containing the random binomial deviates. (Output)
Optional Arguments
NR — Number of random numbers to generate. (Input)
Default: NR = size (IR,1).
FORTRAN 90 Interface
Generic: CALL RNBIN (N, P, IR [])
Specific: The specific interface name is S_RNBIN.
FORTRAN 77 Interface
Single: CALL RNBIN (NR, N, P, IR)
Description
Routine RNBIN generates pseudorandom numbers from a binomial distribution with parameters N and P. N and P must be positive, and P must be less than 1. The probability function (with n = N and p = P) is
for x = 0, 1, 2, n.
The algorithm used depends on the values of n and p. If np < 10 or if p is less than a machine epsilon (AMACH(4) (Reference Material)), the inverse CDF technique is used; otherwise, the BTPE algorithm of Kachitvichyanukul and Schmeiser (see Kachitvichyanukul 1982) is used. This is an acceptance/rejection method using a composition of four regions. (TPE = Triangle, Parallelogram, Exponential, left and right.)
Comments
The routine RNSET can be used to initialize the seed of the random number generator. The routine RNOPT can be used to select the form of the generator.
Example
In this example, RNBIN is used to generate five pseudorandom binomial variates with parameters 20 and 0.5.
 
USE RNBIN_INT
USE UMACH_INT
USE RNSET_INT
 
IMPLICIT NONE
INTEGER NR
PARAMETER (NR=5)
!
INTEGER IR(NR), ISEED, N, NOUT
REAL P
!
CALL UMACH (2, NOUT)
N = 20
P = 0.5
ISEED = 123457
CALL RNSET (ISEED)
CALL RNBIN (N, P, IR)
WRITE (NOUT,99999) IR
99999 FORMAT (' Binomial (20, 0.5) random deviates: ', 5I4)
END
Output
 
Binomial (20, 0.5) random deviates: 14 9 12 10 12
Published date: 03/19/2020
Last modified date: 03/19/2020