Java Code Examples for java.util.SplittableRandom#nextDouble()

The following examples show how to use java.util.SplittableRandom#nextDouble() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SplittableRandomTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 2
Source File: SplittableRandomTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 3
Source File: SplittableRandomTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 4
Source File: SplittableRandomTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 5
Source File: SplittableRandomTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 6
Source File: SplittableRandomTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 7
Source File: SplittableRandomTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 8
Source File: SplittableRandomTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 9
Source File: SplittableRandomTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 10
Source File: SplittableRandomTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeated calls to nextDouble produce at least two distinct results
 */
public void testNextDouble() {
    SplittableRandom sr = new SplittableRandom();
    double f = sr.nextDouble();
    int i = 0;
    while (i < NCALLS && sr.nextDouble() == f)
        ++i;
    assertTrue(i < NCALLS);
}
 
Example 11
Source File: SeededTestData.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
public static <T extends BitmapDataProvider> T randomBitmap(int maxKeys, RoaringBitmapWriter<T> writer) {
  try {
    SplittableRandom random = RNG.get();
    double rleLimit = random.nextDouble();
    double denseLimit = random.nextDouble(rleLimit, 1D);
    return randomBitmap(maxKeys, rleLimit, denseLimit, random, writer);
  } finally {
    RNG.remove();
  }
}
 
Example 12
Source File: SplittableRandomTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeated calls to nextDouble produce at least two distinct results
 */
public void testNextDouble() {
    SplittableRandom sr = new SplittableRandom();
    double f = sr.nextDouble();
    int i = 0;
    while (i < NCALLS && sr.nextDouble() == f)
        ++i;
    assertTrue(i < NCALLS);
}
 
Example 13
Source File: SplittableRandomTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeated calls to nextDouble produce at least two distinct results
 */
public void testNextDouble() {
    SplittableRandom sr = new SplittableRandom();
    double f = sr.nextDouble();
    int i = 0;
    while (i < NCALLS && sr.nextDouble() == f)
        ++i;
    assertTrue(i < NCALLS);
}
 
Example 14
Source File: SplittableRandomTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeated calls to nextDouble produce at least two distinct results
 */
public void testNextDouble() {
    SplittableRandom sr = new SplittableRandom();
    double f = sr.nextDouble();
    int i = 0;
    while (i < NCALLS && sr.nextDouble() == f)
        ++i;
    assertTrue(i < NCALLS);
}
 
Example 15
Source File: SplittableRandomTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeated calls to nextDouble produce at least two distinct results
 */
public void testNextDouble() {
    SplittableRandom sr = new SplittableRandom();
    double f = sr.nextDouble();
    int i = 0;
    while (i < NCALLS && sr.nextDouble() == f)
        ++i;
    assertTrue(i < NCALLS);
}
 
Example 16
Source File: SplittableRandomTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeated calls to nextDouble produce at least two distinct results
 */
public void testNextDouble() {
    SplittableRandom sr = new SplittableRandom();
    double f = sr.nextDouble();
    int i = 0;
    while (i < NCALLS && sr.nextDouble() == f)
        ++i;
    assertTrue(i < NCALLS);
}
 
Example 17
Source File: SplittableRandomTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeated calls to nextDouble produce at least two distinct results
 */
public void testNextDouble() {
    SplittableRandom sr = new SplittableRandom();
    double f = sr.nextDouble();
    int i = 0;
    while (i < NCALLS && sr.nextDouble() == f)
        ++i;
    assertTrue(i < NCALLS);
}
 
Example 18
Source File: SplittableRandomTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeated calls to nextDouble produce at least two distinct results
 */
public void testNextDouble() {
    SplittableRandom sr = new SplittableRandom();
    double f = sr.nextDouble();
    int i = 0;
    while (i < NCALLS && sr.nextDouble() == f)
        ++i;
    assertTrue(i < NCALLS);
}
 
Example 19
Source File: SplittableRandomTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Repeated calls to nextDouble produce at least two distinct results
 */
public void testNextDouble() {
    SplittableRandom sr = new SplittableRandom();
    double f = sr.nextDouble();
    int i = 0;
    while (i < NCALLS && sr.nextDouble() == f)
        ++i;
    assertTrue(i < NCALLS);
}
 
Example 20
Source File: LinearCombinationsTest.java    From commons-numbers with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@MethodSource("provideLinearCombination")
void testArrayVsInline(ND fun) {
    // Assume the instance implements the inline functions
    final TwoD fun2 = (TwoD) fun;
    final ThreeD fun3 = (ThreeD) fun;
    final FourD fun4 = (FourD) fun;

    final SplittableRandom rng = new SplittableRandom();

    double sInline;
    double sArray;
    final double scale = 1e17;
    for (int i = 0; i < 1000; ++i) {
        final double u1 = scale * rng.nextDouble();
        final double u2 = scale * rng.nextDouble();
        final double u3 = scale * rng.nextDouble();
        final double u4 = scale * rng.nextDouble();
        final double v1 = scale * rng.nextDouble();
        final double v2 = scale * rng.nextDouble();
        final double v3 = scale * rng.nextDouble();
        final double v4 = scale * rng.nextDouble();

        // One sum.
        sInline = fun2.value(u1, v1, u2, v2);
        sArray = fun.value(new double[] {u1, u2},
                           new double[] {v1, v2});
        Assertions.assertEquals(sInline, sArray);

        // Two sums.
        sInline = fun3.value(u1, v1, u2, v2, u3, v3);
        sArray = fun.value(new double[] {u1, u2, u3},
                           new double[] {v1, v2, v3});
        Assertions.assertEquals(sInline, sArray);

        // Three sums.
        sInline = fun4.value(u1, v1, u2, v2, u3, v3, u4, v4);
        sArray = fun.value(new double[] {u1, u2, u3, u4},
                           new double[] {v1, v2, v3, v4});
        Assertions.assertEquals(sInline, sArray);
    }
}