本文整理汇总了Java中java.util.concurrent.ThreadLocalRandom.ints方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadLocalRandom.ints方法的具体用法?Java ThreadLocalRandom.ints怎么用?Java ThreadLocalRandom.ints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ThreadLocalRandom
的用法示例。
在下文中一共展示了ThreadLocalRandom.ints方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBadStreamSize
import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
* 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);
}
示例2: testBadStreamBounds
import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
* 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);
}