Example usage for org.apache.commons.math3.random RandomGenerator nextLong

List of usage examples for org.apache.commons.math3.random RandomGenerator nextLong

Introduction

In this page you can find the example usage for org.apache.commons.math3.random RandomGenerator nextLong.

Prototype

long nextLong();

Source Link

Document

Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.

Usage

From source file:com.github.rinde.dynurg.PoissonDynamismExperiment.java

public static void main(String[] args) {
    final RandomGenerator rng = new MersenneTwister(123L);
    final TimeSeriesGenerator nonHomogPoissonGenerator = TimeSeries.nonHomogenousPoisson(LENGTH_OF_DAY,
            IntensityFunctions.sineIntensity().area(NUM_EVENTS / (LENGTH_OF_DAY / INTENSITY_PERIOD))
                    .period(INTENSITY_PERIOD).height(StochasticSuppliers.uniformDouble(-.99, 1.5d))
                    .phaseShift(StochasticSuppliers.uniformDouble(0, INTENSITY_PERIOD))
                    .buildStochasticSupplier());

    final TimeSeriesGenerator homogPoissonGenerator = TimeSeries.homogenousPoisson(LENGTH_OF_DAY, NUM_EVENTS);

    final TimeSeriesGenerator normalGenerator = TimeSeries.normal(LENGTH_OF_DAY, NUM_EVENTS, 2.4 * 60 * 1000);

    final StochasticSupplier<Double> maxDeviation = StochasticSuppliers.normal().mean(1 * 60 * 1000)
            .std(1 * 60 * 1000).lowerBound(0).upperBound(15d * 60 * 1000).buildDouble();
    final TimeSeriesGenerator uniformGenerator = TimeSeries.uniform(LENGTH_OF_DAY, NUM_EVENTS, maxDeviation);

    createDynamismHistogram(nonHomogPoissonGenerator, rng.nextLong(),
            new File(FOLDER + "non-homog-poisson-dynamism.csv"), REPETITIONS);

    createDynamismHistogram(homogPoissonGenerator, rng.nextLong(),
            new File(FOLDER + "homog-poisson-dynamism.csv"), REPETITIONS);

    createDynamismHistogram(normalGenerator, rng.nextLong(), new File(FOLDER + "normal-dynamism.csv"),
            REPETITIONS);//from ww  w  . ja v  a  2 s  .  co m

    createDynamismHistogram(uniformGenerator, rng.nextLong(), new File(FOLDER + "uniform-dynamism.csv"),
            REPETITIONS);

}

From source file:com.github.rinde.rinsim.scenario.generator.LocationsTest.java

static void assertAlwaysEquals(LocationGenerator lg) {
    final RandomGenerator rng = new MersenneTwister(123);
    final List<Point> points = lg.generate(rng.nextLong(), 2);
    for (int i = 0; i < 5; i++) {
        final List<Point> points2 = lg.generate(rng.nextLong(), 2);
        assertEquals(points, points2);/*  w ww  .j a v a  2s  .  c om*/
    }
}

From source file:com.github.rinde.dynurg.PoissonDynamismExperiment.java

static void createDynamismHistogram(TimeSeriesGenerator generator, long seed, File file, int repetitions) {
    try {/* w w w  .j  av a  2 s. co m*/
        Files.createParentDirs(file);
    } catch (final IOException e1) {
        throw new IllegalStateException(e1);
    }
    final RandomGenerator rng = new MersenneTwister(seed);
    final List<Double> values = newArrayList();
    final SummaryStatistics ss = new SummaryStatistics();
    for (int i = 0; i < repetitions; i++) {
        final List<Double> times = generator.generate(rng.nextLong());
        ss.addValue(times.size());
        final double dynamism = Metrics.measureDynamism(times, LENGTH_OF_DAY);
        values.add(dynamism);
    }
    System.out.println(
            file.getName() + " has #events: mean: " + ss.getMean() + " +- " + ss.getStandardDeviation());

    final StringBuilder sb = new StringBuilder();
    sb.append(Joiner.on("\n").join(values));
    try {
        Files.write(sb.toString(), file, Charsets.UTF_8);
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.milaboratory.core.mutations.generator.MutationModels.java

public static NucleotideMutationModel getEmpiricalNucleotideMutationModelWithNoise(RandomGenerator rd,
        double minFactor, double maxFactor) {
    double l = maxFactor - minFactor;
    return new GenericNucleotideMutationModel(
            getEmpiricalNucleotideSubstitutionModelWithNoise(rd, minFactor, maxFactor),
            0.00522 * (minFactor + l * rd.nextDouble()), 0.00198 * (minFactor + l * rd.nextDouble()),
            rd.nextLong());
}

From source file:com.github.rinde.dynurg.Generator.java

/**
 * Generates all scenarios. Each scenario has exactly the same location list.
 * @param rng The master random number generator.
 *//*from  w  ww.  jav  a  2  s .c o  m*/
public static void generateWithFixedLocations(RandomGenerator rng) {
    final List<Point> locations = Locations.builder().min(0d).max(AREA_WIDTH).buildUniform()
            .generate(rng.nextLong(), NUM_ORDERS * 2);

    generate(rng, Locations.builder().min(0d).max(AREA_WIDTH).buildFixed(locations));
}

From source file:com.github.rinde.rinsim.scenario.measure.MetricsTest.java

static Times generateTimes(RandomGenerator rng, double intensity) {
    final ExponentialDistribution ed = new ExponentialDistribution(1000d / intensity);
    ed.reseedRandomGenerator(rng.nextLong());
    final List<Long> times = newArrayList();

    long sum = 0;
    while (sum < 1000) {
        sum += DoubleMath.roundToLong(ed.sample(), RoundingMode.HALF_DOWN);
        if (sum < 1000) {
            times.add(sum);/*from   w w  w.ja  v  a2s . com*/
        }
    }
    return asTimes(1000, times);
}

From source file:com.github.rinde.rinsim.core.model.rand.RandomModelTest.java

static void testUnmodifiable(RandomGenerator rng) {
    boolean fail = false;
    try {//  ww  w  .  j ava2  s. c o  m
        rng.setSeed(0);
    } catch (final UnsupportedOperationException e) {
        fail = true;
    }
    assertTrue(fail);
    fail = false;
    try {
        rng.setSeed(new int[] { 0 });
    } catch (final UnsupportedOperationException e) {
        fail = true;
    }
    assertTrue(fail);
    fail = false;
    try {
        rng.setSeed(123L);
    } catch (final UnsupportedOperationException e) {
        fail = true;
    }
    assertTrue(fail);
    fail = false;

    rng.nextBoolean();
    rng.nextBytes(new byte[] {});
    rng.nextDouble();
    rng.nextFloat();
    rng.nextGaussian();
    rng.nextInt();
    rng.nextInt(1);
    rng.nextLong();
}

From source file:com.milaboratory.core.io.util.AbstractRandomAccessReaderTest.java

@Test
public void test3() throws Exception {
    RandomGenerator rnd = new Well1024a();
    File tempFile = createRandomFile(rnd.nextLong());
    String[] allLines = getAllLines(tempFile);
    for (int step = 5; step < 10; step += 2) {
        for (int start = 1; start <= step; ++start) {
            FileIndex index = buildIndex(tempFile, step, start);
            StringReader reader = new StringReader(index, tempFile);
            for (int i = 0; i < allLines.length; ++i) {
                int p = rnd.nextInt(allLines.length);
                Assert.assertEquals(allLines[p], reader.take(p));
            }//from  w  w  w . ja v  a2s .c  o  m
        }
    }
    tempFile.delete();
}

From source file:com.github.rinde.rinsim.scenario.generator.TimeSeriesTest.java

/**
 * Test whether the number of events filter works.
 *///  w  ww  .  ja  v  a2s .  c  o m
@Test
public void testFilter() {
    final TimeSeriesGenerator original = homogenousPoisson(500, 20);
    final TimeSeriesGenerator filtered = filter(original, numEventsPredicate(20));
    final RandomGenerator rng = new MersenneTwister(123L);
    for (int i = 0; i < 10; i++) {
        assertEquals(20, filtered.generate(rng.nextLong()).size());
    }
}

From source file:com.github.rinde.rinsim.scenario.generator.PoissonProcessTest.java

/**
 * Tests determinism of arrival times generators, given the same random number
 * generator and seed they should always return the same sequence.
 *//* w w w  .j a v  a  2  s.c  om*/
@Test
public void determinismTest() {
    final RandomGenerator outer = new MersenneTwister(123);

    for (int i = 0; i < 100; i++) {
        final long seed = outer.nextLong();
        final RandomGenerator inner = new MersenneTwister(seed);
        final List<Double> list1 = poisson.generate(inner.nextLong());
        for (int j = 0; j < 100; j++) {
            inner.setSeed(seed);
            final List<Double> list2 = poisson.generate(inner.nextLong());
            assertEquals(list1, list2);
        }
    }
}