List of usage examples for org.apache.commons.math3.random RandomGenerator setSeed
void setSeed(long seed);
long seed. From source file:cz.cuni.mff.d3s.spl.utils.DistributionUtils.java
/** Create empirical distribution from given samples. * /*from ww w . j av a2 s.co m*/ * @param samples Samples (does not need to be distinct) to use. * @return Empirical distribution built from the samples. */ public static EmpiricalDistribution makeEmpirical(double[] samples) { /* Be deterministic for now. */ RandomGenerator gen = new JDKRandomGenerator(); gen.setSeed(0); EmpiricalDistribution result = new EmpiricalDistribution(samples.length / 10 + 1, gen); result.load(samples); return result; }
From source file:com.anhth12.lambda.common.random.RandomManager.java
/** * <em>Only call in test code.</em> Causes all known instances of {@link RandomGenerator}, * and future ones, to be started from a fixed seed. This is useful for making * tests deterministic./*from w ww . ja v a 2s.co m*/ */ public static void useTestSeed() { useTestSeed = true; Collection<RandomGenerator> instances = INSTANCES.get(); if (instances != null) { synchronized (instances) { for (RandomGenerator random : instances) { random.setSeed(TEST_SEED); } instances.clear(); } INSTANCES.clear(); } }
From source file:com.cloudera.oryx.common.random.RandomManager.java
/** * <em>Only call in test code.</em> Causes all known instances of {@link RandomGenerator}, and future ones, * to be started from a fixed seed. This is useful for making tests deterministic. *///from w ww. jav a 2 s . c om public static void useTestSeed() { useTestSeed = true; synchronized (INSTANCES) { for (RandomGenerator random : INSTANCES.keySet()) { random.setSeed(TEST_SEED); } INSTANCES.clear(); } }
From source file:com.github.aptd.simulation.CMain.java
private static void execute(final CommandLine p_cli) { final double l_changetimemin = Double.parseDouble(p_cli.getOptionValue("changetimemin", "100")); final double l_changetimemax = Double.parseDouble(p_cli.getOptionValue("changetimemax", "100")); final int l_numberofpassengers = Integer.parseUnsignedInt(p_cli.getOptionValue("numberofpassengers", "20")); final double l_lightbarrierminfreetime = Double .parseDouble(p_cli.getOptionValue("lightbarrierminfreetime", "3.0")); final double l_delayseconds = Double.parseDouble(p_cli.getOptionValue("delayseconds", "0.0")); // load configuration CConfiguration.INSTANCE.loadfile(p_cli.getOptionValue("config", "")); // execute experiments in batch processing and starts http server new Thread(() -> datamodel(p_cli).map(i -> i.getLeft().model().get( EFactory.from(CConfiguration.INSTANCE.getOrDefault("local", "runtime", "type")).factory(), i.getRight(),/*from ww w . j a v a2 s .c o m*/ p_cli.hasOption("iteration") ? Long.parseLong(p_cli.getOptionValue("iteration")) : (long) CConfiguration.INSTANCE.getOrDefault(0, "default", "iteration"), !p_cli.hasOption("sequential") && CConfiguration.INSTANCE.<Boolean>getOrDefault(true, "runtime", "parallel"), p_cli.hasOption("timemodel") ? p_cli.getOptionValue("timemodel") : "step", () -> { if (l_changetimemax <= l_changetimemin) return new ConstantRealDistribution(l_changetimemin); final RandomGenerator l_randomgenerator = new JDKRandomGenerator(); l_randomgenerator.setSeed(Long.parseLong(p_cli.getOptionValue("changetimeseed", "1"))); return new UniformRealDistribution(l_randomgenerator, l_changetimemin, l_changetimemax); }, l_numberofpassengers, l_lightbarrierminfreetime, l_delayseconds)) .forEach(i -> ERuntime.LOCAL.get().execute(i))).start(); // start http server if possible if (p_cli.hasOption("interactive")) CHTTPServer.execute(); }
From source file:com.github.rinde.rinsim.core.model.rand.RandomModelTest.java
static void testUnmodifiable(RandomGenerator rng) { boolean fail = false; try {//w w w . j a v a 2 s.co 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:io.coala.random.impl.RandomNumberStreamFactoryWell19937c.java
@Override public RandomNumberStream create(final RandomNumberStreamID id, final Number seed) { final RandomGenerator rng = new Well19937c(); rng.setSeed(seed.intValue()); return RandomNumberStream.Util.asStream(id, rng); }
From source file:io.coala.random.impl.RandomNumberStreamFactoryJDK.java
@Override public RandomNumberStream create(final RandomNumberStreamID id, final Number seed) { final RandomGenerator rng = new JDKRandomGenerator(); rng.setSeed(seed.intValue()); return RandomNumberStream.Util.asStream(id, rng); }
From source file:com.github.joulupunikki.math.random.BitsStreamGenerator64Test.java
@Override protected RandomGenerator makeGenerator() { RandomGenerator generator = new TestBitStreamGenerator64(); generator.setSeed(1000); return generator; }
From source file:com.github.joulupunikki.math.random.BitsStreamGenerator64SeedTest.java
@Override protected RandomGenerator makeGenerator() { RandomGenerator generator = new TestBitStreamGenerator64Seed(); generator.setSeed(1); return generator; }
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. *///from w w w .j av a 2 s . c o m @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); } } }