/** {@inheritDoc} */ public void setSeed(int[] seed) { if (randomGenerator != null) { // required to avoid NPE in constructor randomGenerator.setSeed(seed); } }
/** * Reseed the random generator used to generate samples. * * @param seed the new seed */ public void reseedRandomGenerator(long seed) { random.setSeed(seed); }
@Override public void setSeed(long seed) { // Since this will be called by the java.util.Random() constructor before we construct // the delegate... and because we don't actually care about the result of this for our // purpose: if (random != null) { random.setSeed(seed); } }
/** * {@inheritDoc} */ public synchronized void setSeed(int[] seed) { wrapped.setSeed(seed); }
/** * {@inheritDoc} */ public synchronized void setSeed(long seed) { wrapped.setSeed(seed); }
/** {@inheritDoc} */ @Override public void setSeed(long seed) { if (randomGenerator != null) { // required to avoid NPE in constructor randomGenerator.setSeed(seed); } }
/** * {@inheritDoc} */ public synchronized void setSeed(int seed) { wrapped.setSeed(seed); }
/** {@inheritDoc} */ public void setSeed(int seed) { if (randomGenerator != null) { // required to avoid NPE in constructor randomGenerator.setSeed(seed); } }
/** {@inheritDoc} */ public void reseedRandomGenerator(long seed) { random.setSeed(seed); }
/** * Reseeds the secure random number generator with the current time in * milliseconds. * <p> * Will create and initialize if null. * </p> */ public void reSeedSecure() { getSecRan().setSeed(System.currentTimeMillis()); }
@Override public void setSeed(int seed) { this.seed = (long) seed; getRandomGenerator().setSeed(seed); }
@Override public void setSeed(long seed) { this.seed = seed; getRandomGenerator().setSeed(seed); }
/** {@inheritDoc} */ public void reseedRandomGenerator(long seed) { random.setSeed(seed); randomData.reSeed(seed); }
/** * Reseeds the secure random number generator with the supplied seed. * <p> * Will create and initialize if null. * </p> * * @param seed the seed value to use */ public void reSeedSecure(long seed) { getSecRan().setSeed(seed); }
/** * Reseeds the random number generator with * {@code System.currentTimeMillis() + System.identityHashCode(this))}. */ public void reSeed() { getRandomGenerator().setSeed(System.currentTimeMillis() + System.identityHashCode(this)); }
/** * Reseeds the random number generator with the supplied seed. * <p> * Will create and initialize if null. * </p> * * @param seed the seed value to use */ public void reSeed(long seed) { getRandomGenerator().setSeed(seed); }
/** {@inheritDoc} */ public void reseedRandomGenerator(long seed) { random.setSeed(seed); randomData.reSeed(seed); }
RandomWrapper() { random = new MersenneTwister(); random.setSeed(System.currentTimeMillis() + System.identityHashCode(random)); }
/** * <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. */ public static void useTestSeed() { useTestSeed = true; Collection<RandomGenerator> instances = INSTANCES.get(); if (instances != null) { synchronized (instances) { instances.forEach(random -> random.setSeed(TEST_SEED)); instances.clear(); } INSTANCES.clear(); } }
/** * Returns the SecureRandom used to generate secure random data. * <p> * Creates and initializes if null. Uses * {@code System.currentTimeMillis() + System.identityHashCode(this)} as the default seed. * </p> * * @return the SecureRandom used to generate secure random data, wrapped in a * {@link RandomGenerator}. */ private RandomGenerator getSecRan() { if (secRand == null) { secRand = RandomGeneratorFactory.createRandomGenerator(new SecureRandom()); secRand.setSeed(System.currentTimeMillis() + System.identityHashCode(this)); } return secRand; } }