/** * Create a NaturalRanking with the given TiesStrategy. * * @param tiesStrategy the TiesStrategy to use */ public NaturalRanking(TiesStrategy tiesStrategy) { super(); this.tiesStrategy = tiesStrategy; nanStrategy = DEFAULT_NAN_STRATEGY; randomData = new RandomDataGenerator(); }
/** * @param rdg random number generator to use * @return a hyperparameter value chosen uniformly at random from the range */ @Override public Integer getRandomValue(RandomDataGenerator rdg) { if (max == min) { return min; } return rdg.nextInt(min, max); }
/** {@inheritDoc} */ public long nextLong(long lower, long upper) throws NumberIsTooLargeException { return delegate.nextLong(lower, upper); }
/** {@inheritDoc} */ public long nextLong(final long lower, final long upper) throws NumberIsTooLargeException { if (lower >= upper) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper, false); } final long max = (upper - lower) + 1; if (max <= 0) { // the range is too wide to fit in a positive long (larger than 2^63); as it covers // more than half the long range, we use directly a simple rejection method final RandomGenerator rng = getRandomGenerator(); while (true) { final long r = rng.nextLong(); if (r >= lower && r <= upper) { return r; } } } else if (max < Integer.MAX_VALUE){ // we can shift the range and generate directly a positive int return lower + getRandomGenerator().nextInt((int) max); } else { // we can shift the range and generate directly a positive long return lower + nextLong(getRandomGenerator(), max); } }
/** * @param rdg random number generator to use * @return a hyperparameter value chosen uniformly at random from the range */ @Override public Double getRandomValue(RandomDataGenerator rdg) { if (max == min) { return min; } return rdg.nextUniform(min, max, true); }
@Override public Date getRandomValue() { long minDateTime = minDate.getTime(); long maxDateTime = maxDate.getTime(); long randomDateTime = new RandomDataGenerator().nextLong(minDateTime, maxDateTime); return new Date(randomDateTime); }
@Override public <T> List<T> populateBeans(final Class<T> type, final String... excludedFields) { int size = new RandomDataGenerator().nextInt(1, Short.MAX_VALUE); return populateBeans(type, size, excludedFields); }
private void changeSetting(RandomDataGenerator random, State state, Environment env, Properties props) throws Exception { // pick a random property int choice = random.nextInt(0, settings.length - 1); Setting setting = settings[choice]; // generate a random value long newValue = random.nextLong(setting.min, setting.max); state.set(LAST_SETTING, "" + choice); log.debug("Setting " + setting.property.getKey() + " to " + newValue); env.getConnector().instanceOperations().setProperty(setting.property.getKey(), "" + newValue); }
/** * @param rdg random number generator to use * @return a hyperparameter value chosen from Normal(around, step) */ @Override public Double getRandomValue(RandomDataGenerator rdg) { return rdg.nextGaussian(around, step); }
return allCombinations; RandomDataGenerator rdg = new RandomDataGenerator(RandomManager.getRandom()); int[] indices = rdg.nextPermutation(howManyCombos, howMany); List<List<?>> result = new ArrayList<>(indices.length); for (int i = 0; i < indices.length; i++) {
/** {@inheritDoc} */ public long nextSecureLong(final long lower, final long upper) throws NumberIsTooLargeException { if (lower >= upper) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper, false); } final RandomGenerator rng = getSecRan(); final long max = (upper - lower) + 1; if (max <= 0) { // the range is too wide to fit in a positive long (larger than 2^63); as it covers // more than half the long range, we use directly a simple rejection method while (true) { final long r = rng.nextLong(); if (r >= lower && r <= upper) { return r; } } } else if (max < Integer.MAX_VALUE){ // we can shift the range and generate directly a positive int return lower + rng.nextInt((int) max); } else { // we can shift the range and generate directly a positive long return lower + nextLong(rng, max); } }
/** * {@inheritDoc} * <p> * <strong>Algorithm Description</strong>: * <ul><li> For small means, uses simulation of a Poisson process * using Uniform deviates, as described * <a href="http://irmi.epfl.ch/cmos/Pmmi/interactive/rng7.htm"> here.</a> * The Poisson process (and hence value returned) is bounded by 1000 * mean.</li> * * <li> For large means, uses the rejection algorithm described in <br/> * Devroye, Luc. (1981).<i>The Computer Generation of Poisson Random Variables</i> * <strong>Computing</strong> vol. 26 pp. 197-207.</li></ul></p> */ public long nextPoisson(double mean) throws NotStrictlyPositiveException { return delegate.nextPoisson(mean); }
/** * Reseeds the random data generator. * * @param seed Value with which to reseed the {@link RandomDataImpl} * used to generate random data. */ public void reSeed(long seed) { randomData.reSeed(seed); }
/** * Reseeds the random number generator with * {@code System.currentTimeMillis() + System.identityHashCode(this))}. */ public void reSeed() { getRandomGenerator().setSeed(System.currentTimeMillis() + System.identityHashCode(this)); }
RandomDataGenerator generator = new RandomDataGenerator(new Well19937c()); // Unit normal double normDev = generator.nextGaussian(0, 1); // mean = 0.5, std dev = 2 double normDev2 = generator.nextGaussian(0.5, 2); // exponential, mean = 1 double expDev = generator.nextExponential(1);
/** * Gets a uniformly distributed random value with mean = mu. * * @return random uniform value * @throws MathIllegalArgumentException if the underlying random generator thwrows one */ private double getNextUniform() throws MathIllegalArgumentException { return randomData.nextUniform(0, 2 * mu); }
/** * Gets a Gaussian distributed random value with mean = mu * and standard deviation = sigma. * * @return random Gaussian value * @throws MathIllegalArgumentException if the underlying random generator thwrows one */ private double getNextGaussian() throws MathIllegalArgumentException { return randomData.nextGaussian(mu, sigma); }
/** * {@inheritDoc} * <p> * <strong>Algorithm Description</strong>: * <ul><li> For small means, uses simulation of a Poisson process * using Uniform deviates, as described * <a href="http://irmi.epfl.ch/cmos/Pmmi/interactive/rng7.htm"> here.</a> * The Poisson process (and hence value returned) is bounded by 1000 * mean.</li> * * <li> For large means, uses the rejection algorithm described in <br/> * Devroye, Luc. (1981).<i>The Computer Generation of Poisson Random Variables</i> * <strong>Computing</strong> vol. 26 pp. 197-207.</li></ul></p> */ public long nextPoisson(double mean) throws NotStrictlyPositiveException { return delegate.nextPoisson(mean); }
/** * {@inheritDoc} * @since 3.1 */ @Override public void reseedRandomGenerator(long seed) { randomData.reSeed(seed); }
/** * 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); }