Skip to content

Commit 82229c6

Browse files
teryrorvks
authored andcommitted
Add justification for deviating from the reference
1 parent 5ee3ca3 commit 82229c6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

rand_distr/src/hypergeometric.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ impl Hypergeometric {
142142
}
143143
};
144144
// when sampling more than half the total population, take the smaller
145-
// group as sampled instead (we can then return n1-x instead):
145+
// group as sampled instead (we can then return n1-x instead).
146+
//
147+
// Note: the boundary condition given in the paper is `sample_size < n / 2`;
148+
// we're deviating here, because when n is even, it doesn't matter whether
149+
// we switch here or not, but when n is odd `n/2 < n - n/2`, so switching
150+
// when `k == n/2`, we'd actually be taking the _larger_ group as sampled.
146151
let k = if sample_size <= n / 2 {
147152
sample_size
148153
} else {
@@ -406,4 +411,4 @@ mod test {
406411
test_hypergeometric_mean_and_variance(10100, 10000, 1000, &mut rng);
407412
test_hypergeometric_mean_and_variance(100100, 100, 10000, &mut rng);
408413
}
409-
}
414+
}

0 commit comments

Comments
 (0)