Skip to content

Commit ae434cc

Browse files
committed
comments
1 parent a0f9705 commit ae434cc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/test/java/ro/derbederos/untwist/ReversibleMersenneTwisterTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ int[] getMakotoNishimuraTestSeed() {
4545
return ARRAY_SEED;
4646
}
4747

48+
// the below reference values are provided by the original authors
49+
// for the seed array {0x123, 0x234, 0x345, 0x456}
50+
// http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.out
51+
// {0x123, 0x234, 0x345, 0x456}
4852
@Test
4953
public void testMakotoNishimura() {
5054
ReversibleMersenneTwister mt = makeGenerator();
@@ -305,15 +309,15 @@ public void testMakotoNishimura() {
305309
};
306310

307311
for (long expectedInt : refInt) {
308-
int r = mt.nextInt();
309-
assertEquals(expectedInt, (r & 0x7FFFFFFFL) | ((r < 0) ? 0x80000000L : 0x0L));
312+
long r = ((long) mt.nextInt()) & 0xFFFFFFFFL; // poor man unsigned int
313+
assertEquals(expectedInt, r);
310314
}
311315

316+
// {@code genrand_real2} function from the original code
317+
// {@code genrand_int32() * (1.0 / 4294967296.0)}
312318
for (double expectedDouble : refDouble) {
313-
int r = mt.nextInt();
314-
assertEquals(expectedDouble,
315-
((r & 0x7FFFFFFFL) | ((r < 0) ? 0x80000000L : 0x0L)) / 4294967296.0,
316-
1.0e-8);
319+
long r = ((long) mt.nextInt()) & 0xFFFFFFFFL; // poor man unsigned int
320+
assertEquals(expectedDouble, r / 4294967296.0, 1.0e-8);
317321
}
318322
}
319323

0 commit comments

Comments
 (0)