--- jsr166/src/test/tck/SplittableRandomTest.java 2015/09/20 21:16:08 1.19 +++ jsr166/src/test/tck/SplittableRandomTest.java 2016/11/13 03:36:50 1.20 @@ -50,6 +50,41 @@ public class SplittableRandomTest extend Integer.getInteger("SplittableRandomTest.reps", 4); /** + * Repeated calls to next (only accessible via reflection) produce + * at least two distinct results, and repeated calls produce all + * possible values. + */ + public void testNext() throws ReflectiveOperationException { + SplittableRandom rnd = new SplittableRandom(); + try { + java.lang.reflect.Method m + = SplittableRandom.class.getDeclaredMethod( + "next", new Class[] { int.class }); + m.setAccessible(true); + + int i; + { + int val = new java.util.Random().nextInt(4); + for (i = 0; i < NCALLS; i++) { + int q = (int) m.invoke(rnd, new Object[] { 2 }); + if (val == q) break; + } + assertTrue(i < NCALLS); + } + + { + int r = (int) m.invoke(rnd, new Object[] { 3 }); + for (i = 0; i < NCALLS; i++) { + int q = (int) m.invoke(rnd, new Object[] { 3 }); + assertTrue(q < (1<<3)); + if (r != q) break; + } + assertTrue(i < NCALLS); + } + } catch (SecurityException acceptable) {} + } + + /** * Repeated calls to nextInt produce at least two distinct results */ public void testNextInt() {