本文整理匯總了Java中org.apache.commons.math3.random.RandomGenerator.nextBoolean方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomGenerator.nextBoolean方法的具體用法?Java RandomGenerator.nextBoolean怎麽用?Java RandomGenerator.nextBoolean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.random.RandomGenerator
的用法示例。
在下文中一共展示了RandomGenerator.nextBoolean方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testThreadLocalGeneratorOneThread
import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Test
public void testThreadLocalGeneratorOneThread() {
// given
final Supplier generatorSupplier = mock(Supplier.class);
final RandomGenerator randomGeneratorThread1 = mock(RandomGenerator.class);
final RandomGenerator randomGeneratorThread2 = mock(RandomGenerator.class);
given(generatorSupplier.get()).willReturn(randomGeneratorThread1, randomGeneratorThread2);
final RandomGenerator threadLocalRandomGenerator = RandomGenerators.threadLocalGenerator(generatorSupplier);
// when
threadLocalRandomGenerator.nextBoolean();
threadLocalRandomGenerator.nextBoolean();
// then
verify(randomGeneratorThread1, times(2)).nextBoolean();
verify(randomGeneratorThread2, never()).nextBoolean();
}
示例2: testThreadLocalGeneratorTwoThreads
import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Test
public void testThreadLocalGeneratorTwoThreads() throws ExecutionException, InterruptedException {
// given
final Supplier generatorSupplier = mock(Supplier.class);
final RandomGenerator randomGeneratorThread1 = mock(RandomGenerator.class);
final RandomGenerator randomGeneratorThread2 = mock(RandomGenerator.class);
given(generatorSupplier.get()).willReturn(randomGeneratorThread1, randomGeneratorThread2);
final RandomGenerator threadLocalRandomGenerator = RandomGenerators.threadLocalGenerator(generatorSupplier);
// when
Executors.newSingleThreadExecutor().submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
return threadLocalRandomGenerator.nextBoolean();
}
}).get();
threadLocalRandomGenerator.nextBoolean();
// then
verify(randomGeneratorThread1).nextBoolean();
verify(randomGeneratorThread2).nextBoolean();
}
示例3: generate
import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
List<String> elements = new ArrayList<>(n + 2);
elements.add(Integer.toString(id));
int count = 0;
for (int i = 0; i < n; i++) {
boolean positive = random.nextBoolean();
elements.add(positive ? "A" : "B");
if (positive) {
count++;
}
}
elements.add(Integer.toString(count));
return new Pair<>(Integer.toString(id), TextUtils.joinDelimited(elements, ','));
}
示例4: generate
import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
return new Pair<>(Integer.toString(id),
id + "," +
random.nextInt(100) + ',' +
random.nextBoolean() + ',' +
random.nextGaussian());
}
示例5: measureBooleanGeneration
import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
private static Callable<Long> measureBooleanGeneration(final RandomGenerator randomGenerator, final int iterations, final TimeUnit timeUnit) {
return new Callable<Long>() {
@Override
public Long call() throws Exception {
Stopwatch stopwatch = Stopwatch.createStarted();
for (int i = 0; i < iterations; i++) {
randomGenerator.nextBoolean();
}
return stopwatch.elapsed(timeUnit);
}
};
}
示例6: executeRandomized
import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
protected static void executeRandomized(
final int runs, final RandomGenerator rng, final Runnable runnable1, final Runnable runnable2) {
for (int i = 0; i < runs; i++) {
if (rng.nextBoolean()) {
runnable1.run();
runnable2.run();
} else {
runnable2.run();
runnable1.run();
}
}
}
示例7: testRandom
import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Test
public void testRandom() {
final List<Decimal> original = new ArrayList<Decimal>();
original.add(Decimal.TWO);
original.add(Decimal.THREE);
original.add(Decimal.ONE);
original.add(Decimal.TEN);
original.add(Decimal.FIVE);
original.add(Decimal.MINUS_THREE);
for (int i = 0; i < 10000; i++) {
final List<Decimal> input = new ArrayList<Decimal>(original);
final RandomGenerator random = RandomGenerators.newDefaultRandom();
Collections.shuffle(input, new RandomAdaptor(random));
final List<Decimal> sorted = new BisectSortedList<Decimal>(Decimal.COMPARATOR);
// System.out.println("----------------"); //SUPPRESS CHECKSTYLE single line
for (final Decimal in : input) {
final boolean add0 = random.nextBoolean();
if (add0) {
sorted.add(0, in);
// System.out.println("sorted.add(0, new Decimal(\"" + in + "\"));"); //SUPPRESS CHECKSTYLE single line
} else {
sorted.add(in);
// System.out.println("sorted.add(new Decimal(\"" + in + "\"));"); //SUPPRESS CHECKSTYLE single line
}
Decimal.COMPARATOR.assertOrder(sorted, true);
}
}
}
示例8: testRandom
import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Test
public void testRandom() {
final List<Decimal> original = new ArrayList<Decimal>();
original.add(Decimal.TWO);
original.add(Decimal.THREE);
original.add(Decimal.ONE);
original.add(Decimal.TEN);
original.add(Decimal.FIVE);
original.add(Decimal.MINUS_THREE);
for (int i = 0; i < 10000; i++) {
final List<Decimal> input = new ArrayList<Decimal>(original);
final RandomGenerator random = RandomGenerators.newDefaultRandom();
Collections.shuffle(input, new RandomAdaptor(random));
final List<Decimal> sorted = new SortedList<Decimal>(Decimal.COMPARATOR);
// System.out.println("----------------"); //SUPPRESS CHECKSTYLE single line
for (final Decimal in : input) {
final boolean add0 = random.nextBoolean();
if (add0) {
sorted.add(0, in);
// System.out.println("sorted.add(0, new Decimal(\"" + in + "\"));"); //SUPPRESS CHECKSTYLE single line
} else {
sorted.add(in);
// System.out.println("sorted.add(new Decimal(\"" + in + "\"));"); //SUPPRESS CHECKSTYLE single line
}
Decimal.COMPARATOR.assertOrder(sorted, true);
}
}
}