Java Code Examples for java.util.concurrent.ThreadLocalRandom#ints()

The following examples show how to use java.util.concurrent.ThreadLocalRandom#ints() . 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: ThreadLocalRandom8Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invoking sized ints, long, doubles, with negative sizes throws
 * IllegalArgumentException
 */
public void testBadStreamSize() {
    ThreadLocalRandom r = ThreadLocalRandom.current();
    Runnable[] throwingActions = {
        () -> r.ints(-1L),
        () -> r.ints(-1L, 2, 3),
        () -> r.longs(-1L),
        () -> r.longs(-1L, -1L, 1L),
        () -> r.doubles(-1L),
        () -> r.doubles(-1L, .5, .6),
    };
    assertThrows(IllegalArgumentException.class, throwingActions);
}
 
Example 2
Source File: ThreadLocalRandom8Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invoking bounded ints, long, doubles, with illegal bounds throws
 * IllegalArgumentException
 */
public void testBadStreamBounds() {
    ThreadLocalRandom r = ThreadLocalRandom.current();
    Runnable[] throwingActions = {
        () -> r.ints(2, 1),
        () -> r.ints(10, 42, 42),
        () -> r.longs(-1L, -1L),
        () -> r.longs(10, 1L, -2L),
        () -> r.doubles(0.0, 0.0),
        () -> r.doubles(10, .5, .4),
    };
    assertThrows(IllegalArgumentException.class, throwingActions);
}
 
Example 3
Source File: ThreadLocalRandom8Test.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Invoking sized ints, long, doubles, with negative sizes throws
 * IllegalArgumentException
 */
public void testBadStreamSize() {
    ThreadLocalRandom r = ThreadLocalRandom.current();
    Runnable[] throwingActions = {
        () -> r.ints(-1L),
        () -> r.ints(-1L, 2, 3),
        () -> r.longs(-1L),
        () -> r.longs(-1L, -1L, 1L),
        () -> r.doubles(-1L),
        () -> r.doubles(-1L, .5, .6),
    };
    assertThrows(IllegalArgumentException.class, throwingActions);
}
 
Example 4
Source File: ThreadLocalRandom8Test.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Invoking bounded ints, long, doubles, with illegal bounds throws
 * IllegalArgumentException
 */
public void testBadStreamBounds() {
    ThreadLocalRandom r = ThreadLocalRandom.current();
    Runnable[] throwingActions = {
        () -> r.ints(2, 1),
        () -> r.ints(10, 42, 42),
        () -> r.longs(-1L, -1L),
        () -> r.longs(10, 1L, -2L),
        () -> r.doubles(0.0, 0.0),
        () -> r.doubles(10, .5, .4),
    };
    assertThrows(IllegalArgumentException.class, throwingActions);
}