This is an automated email from the ASF dual-hosted git repository.
aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git
The following commit(s) were added to refs/heads/master by this push:
new 8253623d Avoid rejection bound that invalidates the test in
ArraySamplerTest
8253623d is described below
commit 8253623d49466db0d219cadd3e887d315d6d2631
Author: Alex Herbert <[email protected]>
AuthorDate: Tue Feb 17 08:35:57 2026 +0000
Avoid rejection bound that invalidates the test in ArraySamplerTest
---
.../commons/rng/sampling/ArraySamplerTest.java | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git
a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/ArraySamplerTest.java
b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/ArraySamplerTest.java
index 26c607c4..ea469bc2 100644
---
a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/ArraySamplerTest.java
+++
b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/ArraySamplerTest.java
@@ -577,14 +577,24 @@ class ArraySamplerTest {
};
for (int i = 0; i < 100; i++) {
- // Avoid an index bound of 0 or 1 by adding 2
- final int n = 2 + rng.nextInt(ABOVE_BATCH_LIMIT);
- final int[] bound1 = {n * (n - 1)};
+ // Create the bound.
+ // The random output of zero will only be rejected if
+ // unused bits < (2^32 % bound).
+ // Ensure this threshold is above zero
+ int n = 0;
+ int bound = 1;
+ while ((1L << 32) % bound == 0) {
+ // Avoid an index bound of 0 or 1
+ n = rng.nextInt(2, ABOVE_BATCH_LIMIT);
+ bound = n * (n - 1);
+ }
+ final int[] bound1 = {bound};
final int[] i1 = ArraySampler.randomBounded2(n, n - 1, bound1,
rng1);
- final int[] bound2 = {n * (n - 1)};
+ final int[] bound2 = {bound};
final int[] i2 = ArraySampler.randomBounded2(n, n - 1, bound2,
rng2);
- Assertions.assertArrayEquals(i1, i2, "indices");
- Assertions.assertArrayEquals(bound1, bound2, "bounds");
+ final int nn = n;
+ Assertions.assertArrayEquals(i1, i2, () -> "indices: n=" + nn);
+ Assertions.assertArrayEquals(bound1, bound2, () -> "bounds: n=" +
nn);
}
}