Xorshift extends Pseudorandom { @Override long next(long seed) { seed = seed ^ seed << 21; seed = seed ^ seed >>> 35; return seed ^ seed << 4; }    }
@Test public void testNext() throws Exception { assertThat(generator.next(5L), is(178258005L)); assertThat(generator.next(178258005L), is(5651489766934405L)); assertThat(generator.next(5651489766934405L), is(-9127299601691290113L)); assertThat(generator.next(-9127299601691290113L), is(146455018630021125L)); assertThat(generator.next(146455018630021125L), is(2104002940825447L)); }
@Test public void testDistribution() throws Exception { int[] values = new int[10]; long x = System.nanoTime(); for (int i = 0; i < 1000000; i++) { values[(int) ((0x7FFFFFFFFFFFL & (x = generator.next(x))) % 10)]++; } for (int v : values) { assertTrue(v + " was not within 0.1 % of a uniform distribution", 99000 <= v && v <= 101000); } }
@Test public void demonstrateZeroLimitation() { assertThat(new Xorshift().next(0L), is(0L)); }