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


Java RandomGenerator.nextBoolean方法代码示例

本文整理汇总了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();
}
 
开发者ID:asoem,项目名称:greyfish,代码行数:18,代码来源:RandomGeneratorsTest.java

示例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();
}
 
开发者ID:asoem,项目名称:greyfish,代码行数:23,代码来源:RandomGeneratorsTest.java

示例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, ','));
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:16,代码来源:RandomNumericRDFDataGenerator.java

示例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());
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:9,代码来源:DefaultCSVDatumGenerator.java

示例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);
        }
    };
}
 
开发者ID:asoem,项目名称:greyfish,代码行数:13,代码来源:ThreadLocalRandomGeneratorAT.java

示例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();
        }
    }
}
 
开发者ID:asoem,项目名称:greyfish,代码行数:13,代码来源:UnrolledListAT.java

示例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);
        }
    }
}
 
开发者ID:subes,项目名称:invesdwin-util,代码行数:30,代码来源:BisectSortedListTest.java

示例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);
        }
    }
}
 
开发者ID:subes,项目名称:invesdwin-util,代码行数:30,代码来源:SortedListTest.java


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