RNGCS
Sets up table to generate pseudorandom numbers from a general continuous distribution.
Required Arguments
CDF — User‑supplied FUNCTION to compute the cumulative distribution function. The form is CDF(X), where
X — Point at which the distribution function is to be evaluated. (Input)
CDF — Value of the distribution function at X. (Output)
CDF must be declared EXTERNAL in the calling program.
IOPT — Indicator of the extent to which TABLE is initialized prior to calling RNGCS. (Input)
IOPT |
Action |
0 |
RNGCS fills the last four columns of TABLE. The user inputs the points at which the CDF is to be evaluated in the first column of TABLE. These must be in ascending order. |
1 |
RNGCS fills the last three columns of TABLE. CDF is not used and may be a dummy function; instead, the cumulative distribution function is specified in the first two columns of TABLE. The abscissas (in the first column) must be in ascending order and the function must be strictly monotonically increasing. |
TABLE — NDATA by 5 table to be used for interpolation of the cumulative distribution function. (Input and output)
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), and the remaining columns contain values used in interpolation. The first row of TABLE corresponds to the left limit of the support of the distribution and the last row corresponds to the right limit of the support; that is, TABLE(1, 2) = 0.0 and TABLE(NDATA, 2) = 1.0.
Optional Arguments
NDATA — Number of points at which the CDF 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 RNGCS (CDF, IOPT, TABLE [, …])
Specific: The specific interface names are S_RNGCS and D_RNGCS.
FORTRAN 77 Interface
Single: CALL RNGCS (CDF, IOPT, NDATA, TABLE, LDTABL)
Double: The double precision name is DRNGCS.
Description
Routine RNGCS sets up a table that routine RNGCT can use to generate pseudorandom deviates from a continuous distribution. The distribution is specified by its cumulative distribution function, which can be supplied either in tabular form in TABLE or by a FORTRAN function CDF. See the documentation for the routine RNGCT for a description of the method.
Comments
1. Informational error
Type |
Code |
Description |
3 |
1 |
The values in TABLE(1, 2) and/or TABLE(NDATA, 2) are not exactly 0.0 and 1.0, respectively, but they are considered close enough to these values that they are set to these values. |
2. The routine RNGCT uses the table set up by RNGCS to generate random numbers from the distribution with CDF represented in TABLE.
Example
In this example, RNGCS is used to set up a table to generate pseudorandom variates from a beta distribution. This example is continued in the documentation for routine RNGCT to generate the random variates.
USE RNGCS_INT
USE UMACH_INT
IMPLICIT NONE
INTEGER LDTABL
PARAMETER (LDTABL=100)
!
INTEGER I, IOPT, NINT, NOUT
REAL CDF, PIN, QIN, 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)
WRITE (NOUT,99999) (TABLE(I,1),TABLE(I,2),I=1,10)
99999 FORMAT (' First few elements of the table: ', F4.2, F8.4, /, &
(36X,F4.2,F8.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.
First few elements of the table: 0.00 0.0000
0.01 0.0000
0.02 0.0000
0.03 0.0001
0.04 0.0002
0.05 0.0005
0.06 0.0008
0.07 0.0013
0.08 0.0019
0.09 0.0027