Generates pseudorandom numbers from a binomial distribution.
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)
NR — Number of
random numbers to generate. (Input)
Default: NR = size (IR,1).
Generic: CALL RNBIN (N, P, IR [,…])
Specific: The specific interface names i S_RNBIN.
Single: CALL RNBIN (NR, N, P, IR)
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.)
The IMSL 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.
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
Binomial (20, 0.5) random deviates: 14 9 12 10 12
PHONE: 713.784.3131 FAX:713.781.9260 |