View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.rng.simple;
18  
19  import java.util.Arrays;
20  import java.util.List;
21  import java.util.ArrayList;
22  import java.util.Collections;
23  
24  /**
25   * The purpose of this class is to provide the list of all generators
26   * implemented in the library.
27   * The list must be updated with each new RNG implementation.
28   *
29   * @see #list()
30   * @see #list32()
31   * @see #list64()
32   */
33  public final class ProvidersList {
34      /** List of all RNGs implemented in the library. */
35      private static final List<Data> LIST = new ArrayList<>();
36      /** List of 32-bits based RNGs. */
37      private static final List<Data> LIST32 = new ArrayList<>();
38      /** List of 64-bits based RNGs. */
39      private static final List<Data> LIST64 = new ArrayList<>();
40  
41      static {
42          try {
43              // "int"-based RNGs.
44              add(LIST32, RandomSource.JDK, -122333444455555L);
45              add(LIST32, RandomSource.MT, new int[] {-123, -234, -345});
46              add(LIST32, RandomSource.WELL_512_A, new int[] {-23, -34, -45});
47              add(LIST32, RandomSource.WELL_1024_A, new int[] {-1234, -2345, -3456});
48              add(LIST32, RandomSource.WELL_19937_A, new int[] {-2123, -3234, -4345});
49              add(LIST32, RandomSource.WELL_19937_C, new int[] {-123, -234, -345, -456});
50              add(LIST32, RandomSource.WELL_44497_A, new int[] {-12345, -23456, -34567});
51              add(LIST32, RandomSource.WELL_44497_B, new int[] {123, 234, 345});
52              add(LIST32, RandomSource.ISAAC, new int[] {123, -234, 345, -456});
53              add(LIST32, RandomSource.MWC_256, new int[] {12, -1234, -3456, 45678});
54              add(LIST32, RandomSource.KISS, new int[] {12, 1234, 23456, 345678});
55              add(LIST32, RandomSource.XO_RO_SHI_RO_64_S, new int[] {42, 12345});
56              add(LIST32, RandomSource.XO_RO_SHI_RO_64_SS, new int[] {78942, 134});
57              add(LIST32, RandomSource.XO_SHI_RO_128_PLUS, new int[] {565642, 1234, 4534});
58              add(LIST32, RandomSource.XO_SHI_RO_128_SS, new int[] {89, 1234, 6787});
59              add(LIST32, RandomSource.PCG_XSH_RR_32, new long[] {1738L, 1234L});
60              add(LIST32, RandomSource.PCG_XSH_RS_32, new long[] {259L, 2861L});
61              add(LIST32, RandomSource.PCG_MCG_XSH_RS_32, 9678L);
62              add(LIST32, RandomSource.PCG_MCG_XSH_RR_32, 2578291L);
63              // Ensure a high complexity increment is used for the Weyl sequence otherwise
64              // it will not output random data.
65              add(LIST32, RandomSource.MSWS, new long[] {687233648L, 678656564562300L, 0xb5ad4eceda1ce2a9L});
66              add(LIST32, RandomSource.SFC_32, new int[] {-23574234, 7654343});
67              add(LIST32, RandomSource.XO_SHI_RO_128_PP, new int[] {8796823, -3244890, -263842});
68              add(LIST32, RandomSource.PCG_XSH_RR_32_OS, 72346247L);
69              add(LIST32, RandomSource.PCG_XSH_RS_32_OS, -5340832872354L);
70              add(LIST32, RandomSource.L32_X64_MIX, new int[] {2134678128, -162788128});
71              // ... add more here.
72  
73              // "long"-based RNGs.
74              add(LIST64, RandomSource.SPLIT_MIX_64, -988777666655555L);
75              add(LIST64, RandomSource.XOR_SHIFT_1024_S, new long[] {123456L, 234567L, -345678L});
76              add(LIST64, RandomSource.XOR_SHIFT_1024_S_PHI, new long[] {-234567L, -345678L, 3456789L});
77              add(LIST64, RandomSource.TWO_CMRES, 55443322);
78              add(LIST64, RandomSource.TWO_CMRES_SELECT, -987654321, 5, 8);
79              add(LIST64, RandomSource.MT_64, new long[] {1234567L, 2345678L, -3456789L});
80              add(LIST64, RandomSource.XO_RO_SHI_RO_128_PLUS, new long[] {55646L, -456659L, 565656L});
81              add(LIST64, RandomSource.XO_RO_SHI_RO_128_SS, new long[] {45655L, 5454544L, 4564659L});
82              add(LIST64, RandomSource.XO_SHI_RO_256_PLUS, new long[] {11222L, -568989L, -456789L});
83              add(LIST64, RandomSource.XO_SHI_RO_256_SS, new long[] {98765L, -2345678L, -3456789L});
84              add(LIST64, RandomSource.XO_SHI_RO_512_PLUS, new long[] {89932L, -545669L, 4564689L});
85              add(LIST64, RandomSource.XO_SHI_RO_512_SS, new long[] {123L, -654654L, 45646789L});
86              add(LIST64, RandomSource.PCG_RXS_M_XS_64, new long[] {42088L, 69271L});
87              add(LIST64, RandomSource.SFC_64, new long[] {-2357423478979842L, 76543434515L});
88              add(LIST64, RandomSource.XO_RO_SHI_RO_128_PP, new long[] {789741321465L, -461321684612L, -12301654794L});
89              add(LIST64, RandomSource.XO_SHI_RO_256_PP, new long[] {2374243L, -8097397345383L, -223479293943L});
90              add(LIST64, RandomSource.XO_SHI_RO_512_PP, new long[] {-1210684761321465L, -485132198745L, 89942134798523L});
91              add(LIST64, RandomSource.XO_RO_SHI_RO_1024_PP, new long[] {236424345654L, 781544546164721L, -85235476312346L});
92              add(LIST64, RandomSource.XO_RO_SHI_RO_1024_S, new long[] {-1574314L, 7879874453221215L, -7894343883216L});
93              add(LIST64, RandomSource.XO_RO_SHI_RO_1024_SS, new long[] {-41514541234654321L, -12146412316546L, 7984134134L});
94              add(LIST64, RandomSource.PCG_RXS_M_XS_64_OS, -34657834534L);
95              add(LIST64, RandomSource.L64_X128_SS, new long[] {-2379479823783L, -235642384324L, 123678172804389L});
96              add(LIST64, RandomSource.L64_X128_MIX, new long[] {-9723846672394L, 623748567398002L, -23678792345897934L});
97              add(LIST64, RandomSource.L64_X256_MIX, new long[] {236784568279L, 237894579279L, -2378945793L});
98              add(LIST64, RandomSource.L64_X1024_MIX, new long[] {279834579232345L, -2374689578237L, -2347895789327L});
99              add(LIST64, RandomSource.L128_X128_MIX, new long[] {236748567823789L, 237485792375L, 2374895789324L});
100             add(LIST64, RandomSource.L128_X256_MIX, new long[] {-829345782324L, -92304897238673245L, 28974785792345L});
101             add(LIST64, RandomSource.L128_X1024_MIX, new long[] {-6563745678920234L, 7348578274523L, 234523455234L});
102             // ... add more here.
103 
104             // Do not modify the remaining statements.
105             // Complete list.
106             LIST.addAll(LIST32);
107             LIST.addAll(LIST64);
108         } catch (final Exception e) {
109             // CHECKSTYLE: stop Regexp
110             System.err.println("Unexpected exception while creating the list of generators: " + e);
111             e.printStackTrace(System.err);
112             // CHECKSTYLE: resume Regexp
113             throw new RuntimeException(e);
114         }
115     }
116 
117     /**
118      * Class contains only static methods.
119      */
120     private ProvidersList() {}
121 
122     /**
123      * Helper to statisfy Junit requirement that each parameter set contains
124      * the same number of objects.
125      */
126     private static void add(List<Data> list,
127                             RandomSource source,
128                             Object... data) {
129         final RandomSource rng = source;
130         final Object seed = data.length > 0 ? data[0] : null;
131         final Object[] args = data.length > 1 ? Arrays.copyOfRange(data, 1, data.length) : null;
132 
133         list.add(new Data(rng, seed, args));
134     }
135 
136     /**
137      * Subclasses that are "parametric" tests can forward the call to
138      * the "@Parameters"-annotated method to this method.
139      *
140      * @return the list of all generators.
141      */
142     public static Iterable<Data> list() {
143         return Collections.unmodifiableList(LIST);
144     }
145 
146     /**
147      * Subclasses that are "parametric" tests can forward the call to
148      * the "@Parameters"-annotated method to this method.
149      *
150      * @return the list of 32-bits based generators.
151      */
152     public static Iterable<Data> list32() {
153         return Collections.unmodifiableList(LIST32);
154     }
155 
156     /**
157      * Subclasses that are "parametric" tests can forward the call to
158      * the "@Parameters"-annotated method to this method.
159      *
160      * @return the list of 64-bits based generators.
161      */
162     public static Iterable<Data> list64() {
163         return Collections.unmodifiableList(LIST64);
164     }
165 
166     /**
167      * Helper.
168      * Better not to mix Junit assumptions of the usage of "Object[]".
169      */
170     public static class Data {
171         /** RNG specifier. */
172         private final RandomSource source;
173         /** Seed (constructor's first parameter). */
174         private final Object seed;
175         /** Constructor's additional parameters. */
176         private final Object[] args;
177 
178         /**
179          * @param source RNG specifier.
180          * @param seed Seed (constructor's first parameter).
181          * @param args Constructor's additional parameters.
182          */
183         public Data(RandomSource source,
184                     Object seed,
185                     Object[] args) {
186             this.source = source;
187             this.seed = seed;
188             this.args = args;
189         }
190 
191         /**
192          * Gets the RNG specifier.
193          *
194          * @return RNG specifier.
195          */
196         public RandomSource getSource() {
197             return source;
198         }
199 
200         /**
201          * Gets the seed (constructor's first parameter).
202          *
203          * @return Seed
204          */
205         public Object getSeed() {
206             return seed;
207         }
208 
209         /**
210          * Gets the constructor's additional parameters.
211          *
212          * @return Additional parameters.
213          */
214         public Object[] getArgs() {
215             return args == null ? null : Arrays.copyOf(args, args.length);
216         }
217 
218         @Override
219         public String toString() {
220             return source.toString() + " seed=" + seed + " args=" + Arrays.toString(args);
221         }
222     }
223 }