Author(s): F. James | Library: MATHLIB |
Submitter: | Submitted: 15.09.1978 |
Language: Fortran | Revised: |
Structure:
SUBROUTINE subprograms
User Entry Names: HISRAN, HISPRE
Files Referenced: Printer
External References: LOCATR, RNDM
Usage:
CALL HISPRE(Y,NBINS) | (once for each histogram) | ||
CALL HISRAN(Y,NBINS,XLO,XWID,XRAN) | (for each random number) |
Method:
A uniform random number is generated using RNDM (V104). (The user may therefore use RDMOUT and RDMIN (V104) to restart a run.) The uniform number is then transformed to the user's distribution using the cumulative probability distribution constructed from his histogram. The cumulative distribution is inverted using a binary search for the nearest bin boundary and a linear interpolation within the bin. HISRAN therefore generates a constant density within each bin.
Notes:
HISPRE changes the values Y to form the cumulative distribution which is needed by HISRAN. If Y already contains the cumulative distribution rather than the probability density, then HISPRE should not be called, but in that case Y(NBINS) must be exactly equal to one. Numbers may be drawn from several different distributions in the same run by calling HISRAN with different arrays Y1, Y2, etc. and (if desired) different values of NBINS, XLO, XWID (but always the same values for a given array Y). The routine HISPRE should be used to initialize each array Yi.
The performance of the above method is nearly independent of the shape of the function or number of bins.
Error handling:
If the the input data to HISPRE are not valid (some values negative or all values zero), an error message is printed, the input values are printed, and zero is returned instead of a random number. As many as five such messages may be printed to allow for possible errors in more than one distribution.
If HISPRE is not called, and the input data are not already in
cumulative form, HISRAN performs the initialization itself and
prints a warning message. HISRAN recognizes that the data are not
in cumulative form if .