Generates pseudorandom numbers from a general continuous distribution.
float *imsls_f_random_general_continuous (int n_random, int ndata, float table[],..., 0)
The type double function is imsls_d_random_general_continuous.
int n_random
(Input)
Number of random numbers to generate.
int ndata
(Input)
Number of points at which the CDF is
evaluated for interpolation. ndata must be greater than or equal to 4.
float *table
(Input/Ouput)
ndata by 5 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. This table is set up using routine
imsls_f_continous_table_setup.
An array of length n_random containing the random discrete deviates. To release this space, use free.
int
*imsls_f_random_general_continuous (int
n_random, int
ndata, float
table[],
IMSLS_TABLE_COL_DIM, int
table_col_dim,
IMSLS_RETURN_USER, float r[],
0)
IMSLS_TABLE_COL_DIM, int
table_col_dim (Intput)
Column
dimension of the matrix table.
Default:
table_col_dim = 5
IMSLS_RETURN_USER, float r[]
(Output)
User-supplied array of length n_random containing
the random continuous deviates.
Routine imsls_f_random_general_continuous 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 imsls_f_continuous_table_setup. 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.
In this example, imsls_f_continuous_table_setup is used to set up a table for generation of beta pseudorandom deviates. The CDF for this distribution is computed by the routine imsls_f_beta_cdf (Chapter 11, Probability Distribution Functions and Inverses;). The table contains 100 points at which the CDF is evaluated and that are used for interpolation.
float table[100][5], x = 0.0, *r;
imsls_f_continuous_table_setup(cdf, iopt, ndata, (float*)table);
imsls_random_seed_set(123457);
r = imsls_f_random_general_continuous (5, ndata, table, 0);
imsls_f_write_matrix("Beta (3, 2) random deviates", 5, 1, r, 0);
return imsls_f_beta_cdf(x, 3., 2.);
*** WARNING Error from imsls_f_continuous_table_setup. 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[0][1] = 0.000000e+00 and table[ndata-1][1]= 9.994079e-01.
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |