RNGCT
Generates pseudorandom numbers from a general continuous distribution.
Required Arguments
TABLENDATA by 5 table to be used for interpolation of the cumulative distribution function. (Input)
The first column of TABLE contains abscissas of the cumulative distribution function in ascending order, the second column contains the values of the CDF (which must be strictly increasing beginning with 0.0 and ending at 1.0) and the remaining columns contain values used in interpolation. This table is set up using routine RNGCS.
R — Vector of length NR containing the random deviates. (Output)
Optional Arguments
NR — Number of random numbers to generate. (Input)
Default: NR = size (R,1).
NDATA — Number of points at which the cumulative distribution function is evaluated for interpolation. (Input)
NDATA must be greater than or equal to 4.
Default: NDATA = size (TABLE,1).
LDTABL — Leading dimension of TABLE exactly as specified in the dimension statement in the calling program. (Input)
Default: LDTABL = size (TABLE,1).
FORTRAN 90 Interface
Generic: CALL RNGCT (TABLE, R [])
Specific: The specific interface names are S_RNGCT and D_RNGCT.
FORTRAN 77 Interface
Single: CALL RNGCT (NR, NDATA, TABLE, LDTABL, R)
Double: The double precision name is DRNGCT.
Description
Routine RNGCT generates pseudorandom numbers from a continuous distribution using the inverse CDF technique, by interpolation of points of the distribution function given in TABLE, which is set up by routine RNGCS. A strictly monotone increasing distribution function is assumed. The interpolation is by an algorithm attributable to Akima (1970), using piecewise cubics. The use of this technique for generation of random numbers is due to Guerra, Tapia, and Thompson (1976), who give a description of the algorithm and accuracy comparisons between this method and linear interpolation. The relative errors using the Akima interpolation are generally considered very good.
Comments
1. 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.
2. In the interest of efficiency, this routine does only limited error checking. If TABLE is generated by the routine RNGCS, the error checking is sufficient.
Example
In this example, RNGCS is used to set up a table for generation of beta pseudorandom deviates. The CDF for this distribution is computed by the routine BETDF (see Chapter 17, “Probability Distribution Function and Inverses”). The table contains 100 points at which the CDF is evaluated and that are used for interpolation.
 
USE RNGCT_INT
USE UMACH_INT
USE RNGCS_INT
USE RNSET_INT
 
IMPLICIT NONE
INTEGER LDTABL, NR
PARAMETER (LDTABL=100, NR=5)
!
INTEGER I, IOPT, ISEED, NINT, NOUT
REAL CDF, PIN, QIN, R(NR), TABLE(LDTABL,5), X
COMMON /BCOM/ PIN, QIN
EXTERNAL CDF
!
CALL UMACH (2, NOUT)
PIN = 3.0
QIN = 2.0
IOPT = 0
NINT = 100
X = 0.0
! Fill the first column of the table
! with abscissas for interpolation.
DO 10 I=1, NINT
TABLE(I,1) = X
X = X + 0.01
10 CONTINUE
CALL RNGCS (CDF, IOPT, TABLE)
! Initialize seed of random number
! generator.
ISEED = 123457
CALL RNSET (ISEED)
! Now generate the random deviates.
CALL RNGCT (TABLE, R)
WRITE (NOUT,99999) R
99999 FORMAT (' Beta (3,2) random deviates: ', 5F7.4)
END
!
! Beta distribution function
REAL FUNCTION CDF (X)
REAL X
!
REAL BETDF, PIN, QIN
COMMON /BCOM/ PIN, QIN
EXTERNAL BETDF
!
CDF = BETDF(X,PIN,QIN)
RETURN
END
Output
 
*** WARNING ERROR 1 from RNGCS. The values of the CDF in the second
*** column of TABLE did not begin at 0.0 and end at 1.0, but they
*** have been adjusted. Prior to adjustment,
*** TABLE(1,2) = 0.000000E+00 and TABLE(NDATA,2) = 9.994079E-01.
Beta (3,2) random deviates: 0.9208 0.4641 0.7668 0.6536 0.8171
Published date: 03/19/2020
Last modified date: 03/19/2020