use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testNextIntBounded.
/**
* nextInt(bound) returns 0 <= value < bound;
* repeated calls produce at least two distinct results
*/
public void testNextIntBounded() {
SplittableRandom sr = new SplittableRandom();
// sample bound space across prime number increments
for (int bound = 2; bound < MAX_INT_BOUND; bound += 524959) {
int f = sr.nextInt(bound);
assertTrue(0 <= f && f < bound);
int i = 0;
int j;
while (i < NCALLS && (j = sr.nextInt(bound)) == f) {
assertTrue(0 <= j && j < bound);
++i;
}
assertTrue(i < NCALLS);
}
}
use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testBoundedLongs.
/**
* Each of a parallel sized stream of bounded longs is within bounds
*/
public void testBoundedLongs() {
AtomicInteger fails = new AtomicInteger(0);
SplittableRandom r = new SplittableRandom();
long size = 123L;
for (long least = -86028121; least < MAX_LONG_BOUND; least += 1982451653L) {
for (long bound = least + 2; bound > least && bound < MAX_LONG_BOUND; bound += Math.abs(bound * 7919)) {
final long lo = least, hi = bound;
r.longs(size, lo, hi).parallel().forEach(x -> {
if (x < lo || x >= hi)
fails.getAndIncrement();
});
}
}
assertEquals(fails.get(), 0);
}
use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testNextDoubleBounded2.
/**
* nextDouble(least, bound) returns least <= value < bound;
* repeated calls produce at least two distinct results
*/
public void testNextDoubleBounded2() {
SplittableRandom sr = new SplittableRandom();
for (double least = 0.0001; least < 1.0e20; least *= 8) {
for (double bound = least * 1.001; bound < 1.0e20; bound *= 16) {
double f = sr.nextDouble(least, bound);
assertTrue(least <= f && f < bound);
int i = 0;
double j;
while (i < NCALLS && (j = sr.nextDouble(least, bound)) == f) {
assertTrue(least <= j && j < bound);
++i;
}
assertTrue(i < NCALLS);
}
}
}
use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testUnsizedDoublesCount.
/**
* A parallel unsized stream of doubles generates at least 100 values
*/
public void testUnsizedDoublesCount() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.doubles().limit(size).parallel().forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testUnsizedIntsCount.
/**
* A parallel unsized stream of ints generates at least 100 values
*/
public void testUnsizedIntsCount() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.ints().limit(size).parallel().forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
Aggregations