本文整理汇总了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();
}
示例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();
}
示例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);
}
}
示例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);
}
}
}
示例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();
}
示例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));
}
示例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);
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}
示例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;
}
}
示例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);
}
示例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);
}
示例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();
}