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


Java SplittableRandom.nextInt方法代码示例

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


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

示例1: generateRandomString

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * Generates randomStr random string (for Multipart requests)
 * @param lenght the char number of the random string
 * @return the random string
 */
public static String generateRandomString(int lenght) {
    SplittableRandom splittableRandom = new SplittableRandom();
    StringBuffer randomStr = new StringBuffer();
    int randInt, temp;
    for (int i = 0; i < lenght; i++) {
        randInt = splittableRandom.nextInt(0, 2);
        if (randInt == 1) {
            temp = splittableRandom.nextInt('A', 'Z');
        } else {
            temp = splittableRandom.nextInt('a', 'z');
        }
        randomStr.append((char) temp);
    }
    return randomStr.toString();
}
 
开发者ID:rammarj,项目名称:burp-dynamic-js,代码行数:21,代码来源:Util.java

示例2: generateRandomString

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * Generates a random string (for Multipart requests)
 * @param lenght the char number of the random string
 * @return the random string
 */
public static String generateRandomString(int lenght) {
    SplittableRandom splittableRandom = new SplittableRandom();
    StringBuffer a = new StringBuffer();
    int nextInt, temp;
    for (int i = 0; i < lenght; i++) {
        nextInt = splittableRandom.nextInt(0, 2);
        temp = 'a';
        if (nextInt == 1) {
            temp = splittableRandom.nextInt('A', 'Z');
        } else {
            temp = splittableRandom.nextInt('a', 'z');
        }
        a.append((char) temp);
    }
    return a.toString();
}
 
开发者ID:rammarj,项目名称:burp-reflected-param,代码行数:22,代码来源:Util.java

示例3: testNextIntBounded

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:SplittableRandomTest.java

示例4: testNextIntBounded2

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

示例5: generateRandomString

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * Generates a random string (for Multipart requests)
 * @param lenght the char number of the random string
 * @return the random string
 */
public static String generateRandomString(int lenght) {
    SplittableRandom splittableRandom = new SplittableRandom();
    StringBuffer a = new StringBuffer();
    int nextInt, ext;
    for (int i = 0; i < lenght; i++) {
        nextInt = splittableRandom.nextInt(0, 2);
        ext = 'a';
        if (nextInt == 1) {
            ext = splittableRandom.nextInt('A', 'Z');
        } else {
            ext = splittableRandom.nextInt('a', 'z');
        }
        a.append((char) ext);
    }
    return a.toString();
}
 
开发者ID:rammarj,项目名称:csrf-poc-creator,代码行数:22,代码来源:Util.java

示例6: nextBytes

import java.util.SplittableRandom; //导入方法依赖的package包/类
/** Delegates to {@link SplittableRandom#nextInt(int) SplittableRandom.nextInt(256)}. */
@SuppressWarnings("NumericCastThatLosesPrecision") @Override public void nextBytes(
    final byte[] bytes) {
  final SplittableRandom local = getSplittableRandom();
  for (int i = 0; i < bytes.length; i++) {
    bytes[i] = (byte) (local.nextInt(256));
  }
  debitEntropy(bytes.length * (long) (Byte.SIZE));
}
 
开发者ID:Pr0methean,项目名称:BetterRandom,代码行数:10,代码来源:BaseSplittableRandomAdapter.java

示例7: testNextInt

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

示例8: makeKeys

import java.util.SplittableRandom; //导入方法依赖的package包/类
static Integer[] makeKeys(int n) {
    SplittableRandom rnd = new SplittableRandom();
    Integer[] key = new Integer[n];
    for (int i = 0; i < key.length; ++i)
        key[i] = new Integer(rnd.nextInt());
    return key;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:MapLoops.java

示例9: shuffleKeys

import java.util.SplittableRandom; //导入方法依赖的package包/类
static void shuffleKeys(Integer[] key) {
    SplittableRandom rnd = new SplittableRandom();
    for (int i = key.length; i > 1; --i) {
        int j = rnd.nextInt(i);
        Integer tmp = key[j];
        key[j] = key[i-1];
        key[i-1] = tmp;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:MapLoops.java

示例10: testNextIntBoundNonPositive

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

示例11: testNextIntBadBounds

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

示例12: shuffle

import java.util.SplittableRandom; //导入方法依赖的package包/类
static void shuffle(Object[] keys) {
    SplittableRandom rnd = new SplittableRandom();
    int size = keys.length;
    for (int i=size; i>1; i--) {
        int r = rnd.nextInt(i);
        Object t = keys[i-1];
        keys[i-1] = keys[r];
        keys[r] = t;
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:11,代码来源:MapCheck.java

示例13: testNextIntBoundedNeg

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

示例14: testNextIntBadBounds

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

示例15: FutureLoop

import java.util.SplittableRandom; //导入方法依赖的package包/类
FutureLoop(int nthreads, SplittableRandom rnd) {
    this.nthreads = nthreads;
    this.rnd = rnd;
    barrier = new CyclicBarrier(nthreads+1, timer);
    v = rnd.nextInt();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:CancelledFutureLoops.java


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