RAND_GEN_CONT Function
Generates pseudorandom numbers from a general continuous distribution.
Usage
result = RAND_GEN_CONT(n, table)
Input Parameters
n—Number of random numbers to generate.
table—A two-dimensional array setup using CONT_TABLE to be used for interpolation of the cumulative distribution function. 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.
Returned Value
result—An array of length n containing the random deviates.
Input Keywords
Double—If present and nonzero, double precision is used.
Discussion
Routine RAND_GEN_CONT 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
CONT_TABLE Procedure. 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.
Example
In this example,
RAND_GEN_CONT Function is used to set up a table for generation of beta pseudorandom deviates. The CDF for this distribution is computed by the routine BETACDF. The table contains 100 points at which the CDF is evaluated and that are used for interpolation. Notice that two warnings are issued during the computations for this example.
FUNCTION cdf, x
RETURN, BETACDF(x, 3., 2.)
END
iopt = 0
ndata = 100;
table = FLTARR(100, 5)
x = 0.0;
table(*,0) = FINDGEN(100)/100.
CONT_TABLE, 'cdf', iopt, ndata, table
RANDOMOPT, Set = 123457
r = RAND_GEN_CONT(5, table)
; % BETACDF: Note: STAT_ZERO_AT_X
; Since 'X' = 0.000000e+00 is less than or equal to zero,
; the distribution function is zero at 'x'.
; % CONT_TABLE: Warning: STAT_SECOND_COL_TABLE3
; 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(0, 1) = 0.000000e+00 and
; table(ndata-1, 1)= 9.994079e-01.
PM, r
; PV-WAVE prints the following:
; 0.92079391
; 0.46412855
; 0.76678398
; 0.65357975
; 0.81706959