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

commit 524163e36abdd21c9179275abc175521c89e7c90
Author: aherbert <aherb...@apache.org>
AuthorDate: Mon Oct 21 17:41:05 2019 +0100

    Removed unreachable code from seeding routine.
    
    The code comment is clear that the two values for seeding are positive
    16-bit integers. A test has been added to verify a single bit change in
    the seed makes the output different. Thus all 32-bits of the seed are
    used to construct two 16-bit integers.
---
 .../apache/commons/rng/core/source64/TwoCmres.java |  5 ----
 .../commons/rng/core/source64/TwoCmresTest.java    | 27 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git 
a/commons-rng-core/src/main/java/org/apache/commons/rng/core/source64/TwoCmres.java
 
b/commons-rng-core/src/main/java/org/apache/commons/rng/core/source64/TwoCmres.java
index c9c633f..6fd92ef 100644
--- 
a/commons-rng-core/src/main/java/org/apache/commons/rng/core/source64/TwoCmres.java
+++ 
b/commons-rng-core/src/main/java/org/apache/commons/rng/core/source64/TwoCmres.java
@@ -150,11 +150,6 @@ public class TwoCmres extends LongProvider {
         final int xMax = (seed & 0xffff) + (SEED_GUARD & 0xff);
         final int yMax = (seed >>> 16)   + (SEED_GUARD & 0xff);
 
-        if (xMax < 0 ||
-            yMax < 0) {
-            throw new IllegalStateException(INTERNAL_ERROR_MSG);
-        }
-
         xx = x.getStart();
         for (int i = xMax; i > 0; i--) {
             xx = x.transform(xx);
diff --git 
a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/TwoCmresTest.java
 
b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/TwoCmresTest.java
index a1d8202..f1d2ed5 100644
--- 
a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/TwoCmresTest.java
+++ 
b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/TwoCmresTest.java
@@ -40,6 +40,33 @@ public class TwoCmresTest {
         }
     }
 
+    /**
+     * This test targets the seeding procedure to verify any bit of the input 
seed contributes
+     * to the output. Note: The seeding routine creates 2 16-bit integers from 
the 32-bit seed,
+     * thus a change of any single bit should make a different output.
+     */
+    @Test
+    public void testSeedingWithASingleBitProducesDifferentOutputFromZeroSeed() 
{
+        final int n = 100;
+
+        // Output with a zero seed
+        final long[] values = new long[n];
+        final TwoCmres rng = new TwoCmres(0);
+        for (int i = 0; i < n; i++) {
+            values[i] = rng.nextLong();
+        }
+
+        // Seed with a single bit
+        for (int bit = 0; bit < 32; bit++) {
+            final int seed = 1 << bit;
+
+            final TwoCmres rng1 = new TwoCmres(seed);
+            for (int i = 0; i < n; i++) {
+                Assert.assertNotEquals(values[i], rng1.nextLong());
+            }
+        }
+    }
+
     @Test
     public void testSubcycleGeneratorsMustBeDifferent() {
         final int max = TwoCmres.numberOfSubcycleGenerators();

Reply via email to