當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。