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