Repository: commons-rng Updated Branches: refs/heads/master bc86f3f09 -> 4a33b27b7
Removed method from public API. Javadoc of "TWO_CMRES" documents the valid choices. Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/4a33b27b Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/4a33b27b Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/4a33b27b Branch: refs/heads/master Commit: 4a33b27b711abf1a171b2fdbe852d3d407f69e6a Parents: bc86f3f Author: Gilles <er...@apache.org> Authored: Tue Aug 30 18:19:08 2016 +0200 Committer: Gilles <er...@apache.org> Committed: Tue Aug 30 18:19:08 2016 +0200 ---------------------------------------------------------------------- .../org/apache/commons/rng/RandomSource.java | 17 ++++------ .../rng/internal/source64/TwoCmresTest.java | 33 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-rng/blob/4a33b27b/src/main/java/org/apache/commons/rng/RandomSource.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/rng/RandomSource.java b/src/main/java/org/apache/commons/rng/RandomSource.java index 9b7c120..65d014f 100644 --- a/src/main/java/org/apache/commons/rng/RandomSource.java +++ b/src/main/java/org/apache/commons/rng/RandomSource.java @@ -20,7 +20,6 @@ import java.util.Arrays; import org.apache.commons.rng.internal.ProviderBuilder; import org.apache.commons.rng.internal.BaseProvider; import org.apache.commons.rng.internal.util.SeedFactory; -import org.apache.commons.rng.internal.source64.TwoCmres; /** * This class provides the API for creating generators of random numbers. @@ -255,6 +254,8 @@ public enum RandomSource { XOR_SHIFT_1024_S(ProviderBuilder.RandomSourceInternal.XOR_SHIFT_1024_S), /** * Source of randomness is {@link org.apache.commons.rng.internal.source64.TwoCmres}. + * This generator is equivalent to {@link #TWO_CMRES_SELECT} with the choice of the + * pair {@code (0, 1)} for the two subcycle generators. * <ul> * <li>Native seed type: {@code Integer}.</li> * <li>Native seed size: 1.</li> @@ -264,6 +265,10 @@ public enum RandomSource { /** * Source of randomness is {@link org.apache.commons.rng.internal.source64.TwoCmres}, * with explicit selection of the two subcycle generators. + * The selection of the subcycle generator is by passing its index in the internal + * table, a value between 0 (included) and 13 (included). + * The two indices must be different. + * Different choices of an ordered pair of indices create independent generators. * <ul> * <li>Native seed type: {@code Integer}.</li> * <li>Native seed size: 1.</li> @@ -433,16 +438,6 @@ public enum RandomSource { } /** - * Gets the number of elements of the set of "subcycle" generators from - * which two can be selected in order to create a {@link TwoCmres} RNG. - * - * @return the number of implemented subcycle generators. - */ - public static int numberOfCmresGenerators() { - return TwoCmres.numberOfSubcycleGenerators(); - } - - /** * Saves the state of a RNG. * * @param provider Provider. http://git-wip-us.apache.org/repos/asf/commons-rng/blob/4a33b27b/src/test/java/org/apache/commons/rng/internal/source64/TwoCmresTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/rng/internal/source64/TwoCmresTest.java b/src/test/java/org/apache/commons/rng/internal/source64/TwoCmresTest.java index 16081ae..fc21d20 100644 --- a/src/test/java/org/apache/commons/rng/internal/source64/TwoCmresTest.java +++ b/src/test/java/org/apache/commons/rng/internal/source64/TwoCmresTest.java @@ -49,5 +49,38 @@ public class TwoCmresTest { } } } + + @Test + public void testSubcycleGeneratorsIndex() { + final int seed = 246810; + + // Valid indices are between 0 (included) and max (excluded). + final int max = TwoCmres.numberOfSubcycleGenerators(); + + for (int i = 0; i < max; i++) { + for (int j = 0; j < max; i++) { + if (i != j) { // Subcycle generators must be different. + // Can be instantiated. + new TwoCmres(seed, i, j); + } + } + } + + for (int wrongIndex : new int[] { -1, max }) { + try { + new TwoCmres(seed, wrongIndex, 1); + Assert.fail("Exception expected for index=" + wrongIndex); + } catch (IllegalArgumentException e) { + // Expected. + } + + try { + new TwoCmres(seed, 1, wrongIndex); + Assert.fail("Exception expected for index=" + wrongIndex); + } catch (IllegalArgumentException e) { + // Expected. + } + } + } }