You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/10/21 16:41:10 UTC

[commons-rng] branch master updated (b571fa9 -> 524163e)

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git.


    from b571fa9  Results command to summarise PractRand failure length if all failed.
     new 7f2d39b  Substitute custom rotl function for Long.rotateLeft.
     new 524163e  Removed unreachable code from seeding routine.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/commons/rng/core/source64/TwoCmres.java | 15 +-----------
 .../commons/rng/core/source64/TwoCmresTest.java    | 27 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 14 deletions(-)


[commons-rng] 02/02: Removed unreachable code from seeding routine.

Posted by ah...@apache.org.
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 <ah...@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();


[commons-rng] 01/02: Substitute custom rotl function for Long.rotateLeft.

Posted by ah...@apache.org.
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 7f2d39b7d09be98ba9ffe17e7ebfa2ad31c00438
Author: aherbert <ah...@apache.org>
AuthorDate: Mon Oct 21 17:17:17 2019 +0100

    Substitute custom rotl function for Long.rotateLeft.
---
 .../java/org/apache/commons/rng/core/source64/TwoCmres.java    | 10 +---------
 1 file changed, 1 insertion(+), 9 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 6c50d03..c9c633f 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
@@ -223,19 +223,11 @@ public class TwoCmres extends LongProvider {
         long transform(long state) {
             long s = state;
             s *= multiply;
-            s = rotl(s);
+            s = Long.rotateLeft(s, rotate);
             s -= state;
             return s;
         }
 
-        /**
-         * @param state State.
-         * @return the rotated state.
-         */
-        private long rotl(long state) {
-            return (state << rotate) | (state >>> (64 - rotate));
-        }
-
         /** Factory. */
         static class Factory {
             /** List of good "Cmres" subcycle generators. */