--- a/jdk/test/java/util/concurrent/tck/ThreadLocalRandomTest.java Mon Nov 28 23:43:39 2016 -0800
+++ b/jdk/test/java/util/concurrent/tck/ThreadLocalRandomTest.java Mon Nov 28 23:47:23 2016 -0800
@@ -79,6 +79,41 @@
}
/**
+ * 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 {
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+ try {
+ java.lang.reflect.Method m
+ = ThreadLocalRandom.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() {