当前位置: 首页>>代码示例>>Java>>正文


Java SplittableRandom.nextLong方法代码示例

本文整理汇总了Java中java.util.SplittableRandom.nextLong方法的典型用法代码示例。如果您正苦于以下问题:Java SplittableRandom.nextLong方法的具体用法?Java SplittableRandom.nextLong怎么用?Java SplittableRandom.nextLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.SplittableRandom的用法示例。


在下文中一共展示了SplittableRandom.nextLong方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNextLongBounded

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * nextLong(bound) returns 0 <= value < bound;
 * repeated calls produce at least two distinct results
 */
public void testNextLongBounded() {
    SplittableRandom sr = new SplittableRandom();
    for (long bound = 2; bound < MAX_LONG_BOUND; bound += 15485863) {
        long f = sr.nextLong(bound);
        assertTrue(0 <= f && f < bound);
        int i = 0;
        long j;
        while (i < NCALLS &&
               (j = sr.nextLong(bound)) == f) {
            assertTrue(0 <= j && j < bound);
            ++i;
        }
        assertTrue(i < NCALLS);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:SplittableRandomTest.java

示例2: testNextLongBounded2

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * nextLong(least, bound) returns least <= value < bound;
 * repeated calls produce at least two distinct results
 */
public void testNextLongBounded2() {
    SplittableRandom sr = new SplittableRandom();
    for (long least = -86028121; least < MAX_LONG_BOUND; least += 982451653L) {
        for (long bound = least + 2; bound > least && bound < MAX_LONG_BOUND; bound += Math.abs(bound * 7919)) {
            long f = sr.nextLong(least, bound);
            assertTrue(least <= f && f < bound);
            int i = 0;
            long j;
            while (i < NCALLS &&
                   (j = sr.nextLong(least, bound)) == f) {
                assertTrue(least <= j && j < bound);
                ++i;
            }
            assertTrue(i < NCALLS);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:SplittableRandomTest.java

示例3: testNextLong

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * Repeated calls to nextLong produce at least two distinct results
 */
public void testNextLong() {
    SplittableRandom sr = new SplittableRandom();
    long f = sr.nextLong();
    int i = 0;
    while (i < NCALLS && sr.nextLong() == f)
        ++i;
    assertTrue(i < NCALLS);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:SplittableRandomTest.java

示例4: testSplit1

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * A SplittableRandom produced by split() of a default-constructed
 * SplittableRandom generates a different sequence
 */
public void testSplit1() {
    SplittableRandom sr = new SplittableRandom();
    for (int reps = 0; reps < REPS; ++reps) {
        SplittableRandom sc = sr.split();
        int i = 0;
        while (i < NCALLS && sr.nextLong() == sc.nextLong())
            ++i;
        assertTrue(i < NCALLS);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:SplittableRandomTest.java

示例5: testSplit2

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * A SplittableRandom produced by split() of a seeded-constructed
 * SplittableRandom generates a different sequence
 */
public void testSplit2() {
    SplittableRandom sr = new SplittableRandom(12345);
    for (int reps = 0; reps < REPS; ++reps) {
        SplittableRandom sc = sr.split();
        int i = 0;
        while (i < NCALLS && sr.nextLong() == sc.nextLong())
            ++i;
        assertTrue(i < NCALLS);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:SplittableRandomTest.java

示例6: testNextLongBoundNonPositive

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * nextLong(non-positive) throws IllegalArgumentException
 */
public void testNextLongBoundNonPositive() {
    SplittableRandom sr = new SplittableRandom();
    Runnable[] throwingActions = {
        () -> sr.nextLong(-17L),
        () -> sr.nextLong(0L),
        () -> sr.nextLong(Long.MIN_VALUE),
    };
    assertThrows(IllegalArgumentException.class, throwingActions);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:SplittableRandomTest.java

示例7: testNextLongBadBounds

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * nextLong(least >= bound) throws IllegalArgumentException
 */
public void testNextLongBadBounds() {
    SplittableRandom sr = new SplittableRandom();
    Runnable[] throwingActions = {
        () -> sr.nextLong(17L, 2L),
        () -> sr.nextLong(-42L, -42L),
        () -> sr.nextLong(Long.MAX_VALUE, Long.MIN_VALUE),
    };
    assertThrows(IllegalArgumentException.class, throwingActions);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:SplittableRandomTest.java

示例8: testNextLongBoundedNeg

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * nextLong(negative) throws IllegalArgumentException
 */
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNextLongBoundedNeg() {
    SplittableRandom sr = new SplittableRandom();
    long f = sr.nextLong(-17);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:SplittableRandomTest.java

示例9: testNextLongBadBounds

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * nextLong(least >= bound) throws IllegalArgumentException
 */
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNextLongBadBounds() {
    SplittableRandom sr = new SplittableRandom();
    long f = sr.nextLong(17, 2);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:SplittableRandomTest.java


注:本文中的java.util.SplittableRandom.nextLong方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。