Example usage for org.apache.commons.math.random Well19937c Well19937c

List of usage examples for org.apache.commons.math.random Well19937c Well19937c

Introduction

In this page you can find the example usage for org.apache.commons.math.random Well19937c Well19937c.

Prototype

public Well19937c() 

Source Link

Document

Creates a new random number generator.

Usage

From source file:com.milaboratory.util.MathTest.java

@Test
public void testBinomialLog() throws Exception {
    RandomData rdg = new RandomDataImpl(new Well19937c());
    long n, k;//from w w w . ja  va  2  s.c  o  m
    double func, exact, avrg;
    for (int i = 0; i < 100000; ++i) {
        n = rdg.nextLong(1, 100);
        k = rdg.nextLong(0, n);
        func = Math.binomialCoefficientLog(n, k);
        exact = exactBinomialCoefficientLog(n, k);
        avrg = (func + exact) / 2;
        assertTrue(func == exact || (java.lang.Math.abs(func - exact) / avrg) <= .001);
    }
}

From source file:com.milaboratory.util.MathTest.java

@Test
public void testBinomialLogBig() throws Exception {
    RandomData rdg = new RandomDataImpl(new Well19937c());
    long n, k;/*from w w w  .java 2s . c  om*/
    double func, exact, avrg;
    for (int i = 0; i < 5000; ++i) {
        n = rdg.nextLong(1, 10000);
        k = rdg.nextLong(0, n);
        func = Math.binomialCoefficientLog(n, k);
        exact = exactBinomialCoefficientLog(n, k);
        avrg = (func + exact) / 2;
        assertTrue(func == exact || (java.lang.Math.abs(func - exact) / avrg) <= .001);
    }
}