54 private static final long serialVersionUID = 70510L;
58 private static final int M1 = 2147483647;
59 private static final int M2 = 2147462579;
60 private static final int MASK12 = 511;
61 private static final int MASK13 = 16777215;
62 private static final int MASK2 = 65535;
63 private static final int MULT2 = 21069;
64 private static final double NORM = 4.656612873077392578125e-10;
77 private int[] substream;
78 private static int[] curr_stream = { 12345, 12345, 12345, 12345, 12345, 12345 };
81 private static final int[][] A1p0 = { { 0, 4194304, 129 }, { 1, 0, 0 }, { 0, 1, 0 } };
82 private static final int[][] A2p0 = { { 32768, 0, 32769 }, { 1, 0, 0 }, { 0, 1, 0 } };
84 private static final int[][] A1p72 = { { 1516919229, 758510237, 499121365 }, { 1884998244, 1516919229, 335398200 },
85 { 601897748, 1884998244, 358115744 } };
86 private static final int[][] A2p72 = { { 1228857673, 1496414766, 954677935 }, { 1133297478, 1407477216, 1496414766 },
87 { 2002613992, 1639496704, 1407477216 } };
89 private static final int[][] A1p134 = { { 1702500920, 1849582496, 1656874625 },
90 { 828554832, 1702500920, 1512419905 }, { 1143731069, 828554832, 102237247 } };
91 private static final int[][] A2p134 = { { 796789021, 1464208080, 607337906 }, { 1241679051, 1431130166, 1464208080 },
92 { 1401213391, 1178684362, 1431130166 } };
96 private static void multMatVect(
int[] v,
int[][] A,
int m1,
int[][] B,
int m2) {
97 int[] vv =
new int[3];
98 for (
int i = 0; i < 3; i++)
101 for (
int i = 0; i < 3; i++)
104 for (
int i = 0; i < 3; i++)
107 for (
int i = 0; i < 3; i++)
124 substream =
new int[6];
125 for (
int i = 0; i < 6; i++)
126 stream[i] = curr_stream[i];
130 multMatVect(curr_stream, A1p134, M1, A2p134, M2);
157 throw new IllegalArgumentException(
"Seed must contain 6 values");
158 if (seed[0] == 0 && seed[1] == 0 && seed[2] == 0)
159 throw new IllegalArgumentException(
"The first 3 values must not be 0");
160 if (seed[5] == 0 && seed[3] == 0 && seed[4] == 0)
161 throw new IllegalArgumentException(
"The last 3 values must not be 0");
162 if (seed[0] >= M1 || seed[1] >= M1 || seed[2] >= M1)
163 throw new IllegalArgumentException(
"The first 3 values must be less than " + M1);
164 if (seed[5] >= M2 || seed[3] >= M2 || seed[4] >= M2)
165 throw new IllegalArgumentException(
"The last 3 values must be less than " + M2);
166 for (
int i = 0; i < 6; ++i)
167 curr_stream[i] = seed[i];
184 throw new IllegalArgumentException(
"Seed must contain 6 values");
185 if (seed[0] == 0 && seed[1] == 0 && seed[2] == 0)
186 throw new IllegalArgumentException(
"The first 3 values must not be 0");
187 if (seed[3] == 0 && seed[4] == 0 && seed[5] == 0)
188 throw new IllegalArgumentException(
"The last 3 values must not be 0");
189 if (seed[0] >= M1 || seed[1] >= M1 || seed[2] >= M1)
190 throw new IllegalArgumentException(
"The first 3 values must be less than " + M1);
191 if (seed[3] >= M2 || seed[4] >= M2 || seed[5] >= M2)
192 throw new IllegalArgumentException(
"The last 3 values must be less than " + M2);
193 for (
int i = 0; i < 6; ++i)
199 for (
int i = 0; i < 6; i++)
200 substream[i] = stream[i];
214 multMatVect(substream, A1p72, M1, A2p72, M2);
226 return new int[] { x11, x12, x13, x21, x22, x23 };
237 retour.substream =
new int[6];
238 retour.stream =
new int[6];
239 for (
int i = 0; i < 6; i++) {
240 retour.substream[i] = substream[i];
241 retour.stream[i] = stream[i];
248 return "The state of the MRG31k3p is: " + x11 +
", " + x12 +
", " + x13 +
"; " + x21 +
", " + x22 +
", "
251 return "The state of " + name +
" is: " + x11 +
", " + x12 +
", " + x13 +
"; " + x21 +
", " + x22 +
", "
259 y1 = ((x12 & MASK12) << 22) + (x12 >>> 9) + ((x13 & MASK13) << 7) + (x13 >>> 24);
260 if (y1 < 0 || y1 >= M1)
263 if (y1 < 0 || y1 >= M1)
271 y1 = ((x21 & MASK2) << 15) + (MULT2 * (x21 >>> 16));
272 if (y1 < 0 || y1 >= M2)
274 y2 = ((x23 & MASK2) << 15) + (MULT2 * (x23 >>> 16));
275 if (y2 < 0 || y2 >= M2)
278 if (y2 < 0 || y2 >= M2)
281 if (y2 < 0 || y2 >= M2)
290 return (x11 - x21 + M1) * NORM;
292 return (x11 - x21) * NORM;