Give a method for simulating a hypergeometric random variable.
If a random sample of size n is chosen from a set of N + M items of which N are acceptable, then X, the number of acceptable items in the sample, is such that
P\{X=k\}=\left(\begin{array}{l}N\\k\end{array}\right)\left(\begin{array}{c}M \\n-k\end{array}\right)\bigg/\left(\begin{array}{c}N+M \\k\end{array}\right)To simulate X, note that if
I_{j}= \begin{cases}1, & \text { if the } j \text { th selection is acceptable } \\ 0, & \text { otherwise }\end{cases}then
P\left\{I_{j}=1|I_{1}, \ldots, I_{j-1}\right\}=\frac{N-\sum_{1}^{j-1} I_{i}}{N+M-(j-1)}Hence, we can simulate I1, . . . , In by generating random numbers U1, . . . ,Un and then setting
I_{j}= \begin{cases}1, & \text { if } U_{j}<\frac{N-\sum_{1}^{j-1} I_{i}}{N+M-(j-1)} \\ 0, & \text { otherwise }\end{cases}and X=\sum_{j=1}^{n} I_{j} has the desired distribution. Another way is to let
X_{j}= \begin{cases}1, & \text { the } j \text { th acceptable item is in the sample } \\ 0, & \text { otherwise }\end{cases}and then simulate X1, . . . , XN by generating random numbers U1, . . . ,UN and then setting
X_{j}= \begin{cases}1, & \text { if } U_{j}<\frac{n-\sum_{i=1}^{j-1} X_{i}}{N+M-(j-1)} \\ 0, & \text { otherwise }\end{cases}and X=\sum_{j=1}^{N} X_{j} then has the desired distribution. The former method is preferable when n ≤ N and the latter when N ≤ n.