I'm writing a small statistics library currently. One of the algorithms I'm implementing has two variants: one that samples the hypergeometric distribution and one that samples the negative hypergeometric distribution. I've implemented and optimized the HGD variant, using the H2PEC algorithm for sampling. I'm wondering, though, if there is an equivalent fast sampling algorithm for the NHGD. Alternatively, is there a way to change H2PEC so that it efficiently samples the NHGD?