Skip to content

Commit

Permalink
RNG-76: Added primitive long constructor to SplitMix64
Browse files Browse the repository at this point in the history
  • Loading branch information
aherbert committed Aug 22, 2019
1 parent 6349c05 commit 66d01dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -32,12 +32,23 @@ public class SplitMix64 extends LongProvider {
/** State. */
private long state;

/**
* Creates a new instance.
*
* @param seed Initial seed.
*/
public SplitMix64(long seed) {
state = seed;
}

/**
* Creates a new instance.
*
* @param seed Initial seed.
*/
public SplitMix64(Long seed) {
// Support for Long to allow instantiation through the
// rng.simple.RandomSource factory methods.
setSeedInternal(seed);
}

Expand All @@ -47,7 +58,7 @@ public SplitMix64(Long seed) {
* @param seed Seed.
*/
private void setSeedInternal(Long seed) {
state = seed;
state = seed.longValue();
}

/** {@inheritDoc} */
Expand Down
Expand Up @@ -35,6 +35,11 @@ public void testReferenceCode() {
0x24b5d9d7a00a3140L, 0x79d983d781a34a3cL, 0x582e4a84d595f5ecL, 0x7316fe8b0f606d20L,
};

RandomAssert.assertEquals(expectedSequence, new SplitMix64(0x1a2b3c4d5e6f7531L));
final long seed = 0x1a2b3c4d5e6f7531L;

RandomAssert.assertEquals(expectedSequence, new SplitMix64(seed));

// Test with Long
RandomAssert.assertEquals(expectedSequence, new SplitMix64(Long.valueOf(seed)));
}
}

0 comments on commit 66d01dd

Please sign in to comment.