Generates pseudorandom numbers from a hypergeometric distribution.
#include <imsls.h>
int
*imsls_f_random_hypergeometric (int
n_random,
int
n, int m,
int l, ..., 0)
The type double function is imsls_d_random_hypergeometric.
int n_random
(Input)
Number of random numbers to generate.
int n
(Input)
Number of items in the sample. Parameter n must be
positive.
int m
(Input)
Number of special items in the population, or lot. Parameter m must be
positive.
int l
(Input)
Number of items in the lot. Parameter l must be greater than
both n and m.
An integer array of length n_random containing the random hypergeometric deviates.
#include <imsls.h>
int
*imsls_f_random_hypergeometric (int n_random, int n, int m,
int l,
IMSLS_RETURN_USER, int ir[],
0)
IMSLS_RETURN_USER,
int
ir[] (Output)
User-supplied integer array of length n_random containing
the random hypergeometric deviates.
Function imsls_f_random_hypergeometric generates pseudorandom numbers from a hypergeometric distribution with parameters N, M, and L. The hypergeometric random variable X can be thought of as the number of items of a given type in a random sample of size N that is drawn without replacement from a population of size L containing M items of this type. The probability function is
for x = max (0, N − L + M), 1, 2, …, min (N, M)
If the hypergeometric probability function with parameters N, M, and L evaluated at N − L + M (or at 0 if this is negative) is greater than the machine epsilon (see imsls_f_machine, Chapter 15, “Utilities”;), and less than 1.0 minus the machine epsilon, then imsls_f_random_hypergeometric uses the inverse CDF technique. The routine recursively computes the hypergeometric probabilities, starting at x = max (0, N − L + M) and using the ratio
(see Fishman 1978, p. 475).
If the hypergeometric probability function is too small or too close to 1.0, the imsls_f_random_hypergeometric generates integer deviates uniformly in the interval [1, L − i] for i = 0, 1, ..., and at the i-th step, if the generated deviate is less than or equal to the number of special items remaining in the lot, the occurence of one special item is tallied and the number of remaining special items is decreased by one. This process continues until the sample size of the number of special items in the lot is reached, whichever comes first. This method can be much slower than the inverse CDF technique. The timing depends on N. If N is more than half of L (which in practical examples is rarely the case), the user may wish to modify the problem, replacing N by L − N, and to consider the generated deviates to be the number of special items not included in the sample.
In this example, imsls_f_random_hypergeometric generates five pseudorandom hypergeometric deviates from a hypergeometric distribution to simulate taking random samples of size 4 from a lot containing 20 items, of which 12 are defective. The resulting hypergeometric deviates represent the numbers of defectives in each of the five samples of size 4.
#include <imsls.h>
#include <stdio.h>
void main()
{
int n_random = 5;
int n = 4;
int m = 12;
int l = 20;
int *ir;
imsls_random_seed_set(123457);
ir = imsls_f_random_hypergeometric(n_random, n, m, l, 0);
imsls_i_write_matrix("Hypergeometric random deviates: ",
1, n_random, ir, IMSLS_NO_COL_LABELS, 0);
}
Hypergeometric random deviates:
4 2 3 3 3
IMSLS_LOT_SIZE_TOO_SMALL The lot size must be greater than the sample size and the number of defectives in the lot. Lot size = #. Sample size = #. Number of defectives in the lot = #.
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |