RNBET
Generates pseudorandom numbers from a beta distribution.
Required Arguments
PIN — First beta distribution parameter. (Input)
PIN must be positive.
QIN — Second beta distribution parameter. (Input)
QIN must be positive.
R — Vector of length NR containing the random standard beta deviates. (Output)
Optional Arguments
NR — Number of random numbers to generate. (Input)
Default: NR = size (R,1).
FORTRAN 90 Interface
Generic: CALL RNBET (PIN, QIN, R [])
Specific: The specific interface names are S_RNBET and D_RNBET.
FORTRAN 77 Interface
Single: CALL RNBET (NR, PIN, QIN, R)
Double: The double precision name is DRNBET.
Description
Routine RNBET generates pseudorandom numbers from a beta distribution with parameters PIN and QIN, both of which must be positive. With p = PIN and q = QIN, the probability density function is
where Γ() is the gamma function.
The algorithm used depends on the values of p and q. Except for the trivial cases of p = 1 or q = 1, in which the inverse CDF method is used, all of the methods use acceptance/rejection. If p and q are both less than 1, the method of Johnk (1964) is used; if either p or q is less than 1 and the other is greater than 1, the method of Atkinson (1979) is used; if both p and q are greater than 1, algorithm BB of Cheng (1978), which requires very little setup time, is used if NR is less than 4; and algorithm B4PE of Schmeiser and Babu (1980) is used if NR is greater than or equal to 4. Note that for p and q both greater than 1, calling RNBET in a loop getting less than 4 variates on each call will not yield the same set of deviates as calling RNBET once and getting all the deviates at once.
The values returned in R are less than 1.0 and greater than ɛ, where ɛ is the smallest positive number such that 1.0  ɛ is less than 1.0.
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, RNBET is used to generate five pseudorandom beta (3, 2) variates.
 
USE RNBET_INT
USE UMACH_INT
USE RNSET_INT
 
IMPLICIT NONE
INTEGER NR
PARAMETER (NR=5)
!
INTEGER ISEED, NOUT
REAL PIN, QIN, R(NR)
!
CALL UMACH (2, NOUT)
PIN = 3.0
QIN = 2.0
ISEED = 123457
CALL RNSET (ISEED)
CALL RNBET (PIN, QIN, R)
WRITE (NOUT,99999) R
99999 FORMAT (' Beta (3,2) random deviates: ', 5F7.4)
END
Output
 
Beta (3,2) random deviates: 0.2814 0.9483 0.3984 0.3103 0.8296