/** * @param seed explicit seed for random number generator * @return a new, seeded {@link RandomGenerator} */ public static RandomGenerator getRandom(long seed) { // Don't track these or use the test seed as the caller has manually specified // the seeding behavior return new Well19937c(seed); }
/** * Create a discrete real-valued distribution from the input data. Values are assigned * mass based on their frequency. For example, [0,1,1,2] as input creates a distribution * with values 0, 1 and 2 having probability masses 0.25, 0.5 and 0.25 respectively, * * @param data input dataset * @since 3.6 */ public EnumeratedRealDistribution(final double[] data) { this(new Well19937c(), data); } /**
/** * Construct a KolmogorovSmirnovTest instance with a default random data generator. */ public KolmogorovSmirnovTest() { rng = new Well19937c(); }
/** * Create a discrete integer-valued distribution from the input data. Values are assigned * mass based on their frequency. For example, [0,1,1,2] as input creates a distribution * with values 0, 1 and 2 having probability masses 0.25, 0.5 and 0.25 respectively, * * @param data input dataset * @since 3.6 */ public EnumeratedIntegerDistribution(final int[] data) { this(new Well19937c(), data); }
/** * Creates a mixture model from a list of distributions and their * associated weights. * <p> * <b>Note:</b> this constructor will implicitly create an instance of * {@link Well19937c} as random generator to be used for sampling only (see * {@link #sample()} and {@link #sample(int)}). In case no sampling is * needed for the created distribution, it is advised to pass {@code null} * as random generator via the appropriate constructors to avoid the * additional initialisation overhead. * * @param components List of (weight, distribution) pairs from which to sample. */ public MixtureMultivariateRealDistribution(List<Pair<Double, T>> components) { this(new Well19937c(), components); }
/** * Build a new instance. * <p> * <b>Note:</b> this constructor will implicitly create an instance of * {@link Well19937c} as random generator to be used for sampling only (see * {@link #sample()} and {@link #sample(int)}). In case no sampling is * needed for the created distribution, it is advised to pass {@code null} * as random generator via the appropriate constructors to avoid the * additional initialisation overhead. * * @param mu location parameter * @param c scale parameter * @since 3.4 */ public LevyDistribution(final double mu, final double c) { this(new Well19937c(), mu, c); }
/** * Create a geometric distribution with the given probability of success. * <p> * <b>Note:</b> this constructor will implicitly create an instance of * {@link Well19937c} as random generator to be used for sampling only (see * {@link #sample()} and {@link #sample(int)}). In case no sampling is * needed for the created distribution, it is advised to pass {@code null} * as random generator via the appropriate constructors to avoid the * additional initialisation overhead. * * @param p probability of success. * @throws OutOfRangeException if {@code p <= 0} or {@code p > 1}. */ public GeometricDistribution(double p) { this(new Well19937c(), p); }
/** * Create a uniform real distribution using the given lower and upper * bounds. * <p> * <b>Note:</b> this constructor will implicitly create an instance of * {@link Well19937c} as random generator to be used for sampling only (see * {@link #sample()} and {@link #sample(int)}). In case no sampling is * needed for the created distribution, it is advised to pass {@code null} * as random generator via the appropriate constructors to avoid the * additional initialisation overhead. * * @param lower Lower bound of this distribution (inclusive). * @param upper Upper bound of this distribution (exclusive). * @throws NumberIsTooLargeException if {@code lower >= upper}. */ public UniformRealDistribution(double lower, double upper) throws NumberIsTooLargeException { this(new Well19937c(), lower, upper); }
/** * Build a new instance. * <p> * <b>Note:</b> this constructor will implicitly create an instance of * {@link Well19937c} as random generator to be used for sampling only (see * {@link #sample()} and {@link #sample(int)}). In case no sampling is * needed for the created distribution, it is advised to pass {@code null} * as random generator via the appropriate constructors to avoid the * additional initialisation overhead. * * @param mu location parameter * @param beta scale parameter (must be positive) * @throws NotStrictlyPositiveException if {@code beta <= 0} */ public GumbelDistribution(double mu, double beta) { this(new Well19937c(), mu, beta); }
/** * Build a new instance. * <p> * <b>Note:</b> this constructor will implicitly create an instance of * {@link Well19937c} as random generator to be used for sampling only (see * {@link #sample()} and {@link #sample(int)}). In case no sampling is * needed for the created distribution, it is advised to pass {@code null} * as random generator via the appropriate constructors to avoid the * additional initialisation overhead. * * @param mu location parameter * @param s scale parameter (must be positive) * @throws NotStrictlyPositiveException if {@code beta <= 0} */ public LogisticDistribution(double mu, double s) { this(new Well19937c(), mu, s); }
/** * Build a new instance. * <p> * <b>Note:</b> this constructor will implicitly create an instance of * {@link Well19937c} as random generator to be used for sampling only (see * {@link #sample()} and {@link #sample(int)}). In case no sampling is * needed for the created distribution, it is advised to pass {@code null} * as random generator via the appropriate constructors to avoid the * additional initialisation overhead. * * @param mu location parameter * @param beta scale parameter (must be positive) * @throws NotStrictlyPositiveException if {@code beta <= 0} */ public LaplaceDistribution(double mu, double beta) { this(new Well19937c(), mu, beta); }
/** * Build a new instance. * <p> * <b>Note:</b> this constructor will implicitly create an instance of * {@link Well19937c} as random generator to be used for sampling only (see * {@link #sample()} and {@link #sample(int)}). In case no sampling is * needed for the created distribution, it is advised to pass {@code null} * as random generator via the appropriate constructors to avoid the * additional initialisation overhead. * * @param mu shape parameter * @param omega scale parameter (must be positive) * @param inverseAbsoluteAccuracy the maximum absolute error in inverse * cumulative probability estimates (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}). * @throws NumberIsTooSmallException if {@code mu < 0.5} * @throws NotStrictlyPositiveException if {@code omega <= 0} */ public NakagamiDistribution(double mu, double omega, double inverseAbsoluteAccuracy) { this(new Well19937c(), mu, omega, inverseAbsoluteAccuracy); }
/** * Create a uniform distribution. * * @param lower Lower bound of this distribution (inclusive). * @param upper Upper bound of this distribution (exclusive). * @param inverseCumAccuracy Inverse cumulative probability accuracy. * @throws NumberIsTooLargeException if {@code lower >= upper}. * @deprecated as of 3.2, inverse CDF is now calculated analytically, use * {@link #UniformRealDistribution(double, double)} instead. */ @Deprecated public UniformRealDistribution(double lower, double upper, double inverseCumAccuracy) throws NumberIsTooLargeException { this(new Well19937c(), lower, upper); }
/** * Sets the default generator to a {@link Well19937c} generator seeded with * {@code System.currentTimeMillis() + System.identityHashCode(this))}. */ private void initRan() { rand = new Well19937c(System.currentTimeMillis() + System.identityHashCode(this)); }
static RandomGenerator getUnseededRandom() { RandomGenerator random = new Well19937c(); Collection<RandomGenerator> instances = INSTANCES.get(); if (instances != null) { synchronized (instances) { instances.add(random); } } // else oh well, only matters in tests return random; }
/** * @return a new, seeded {@link RandomGenerator} */ public static RandomGenerator getRandom() { if (useTestSeed) { // No need to track instances anymore return new Well19937c(TEST_SEED); } return getUnseededRandom(); }
/** * Shuffle the entries of the given array. * * @see #shuffle(int[],int,Position,RandomGenerator) * * @param list Array whose entries will be shuffled (in-place). */ public static void shuffle(int[] list) { shuffle(list, new Well19937c()); }
/** {@inheritDoc} */ @Override public Stream<UpstreamEntry> transform(Stream<UpstreamEntry> upstream) { PoissonDistribution poisson = new PoissonDistribution( new Well19937c(seed), subsampleRatio, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS); return upstream.sequential().flatMap(en -> Stream.generate(() -> en).limit(poisson.sample())); } }
/** * Shuffle the entries of the given array. * The {@code start} and {@code pos} parameters select which portion * of the array is randomized and which is left untouched. * * @see #shuffle(int[],int,Position,RandomGenerator) * * @param list Array whose entries will be shuffled (in-place). * @param start Index at which shuffling begins. * @param pos Shuffling is performed for index positions between * {@code start} and either the end (if {@link Position#TAIL}) * or the beginning (if {@link Position#HEAD}) of the array. */ public static void shuffle(int[] list, int start, Position pos) { shuffle(list, start, pos, new Well19937c()); }
static BenchmarkData generate(int param, int howMany, int smallType, int bigType) { IntegerDistribution ud = new UniformIntegerDistribution(new Well19937c(param + 17), Short.MIN_VALUE, Short.MAX_VALUE); ClusteredDataGenerator cd = new ClusteredDataGenerator(); IntegerDistribution p = new UniformIntegerDistribution(new Well19937c(param + 123), SMALLEST_ARRAY, BIGGEST_ARRAY / param); BenchmarkContainer[] smalls = new BenchmarkContainer[howMany]; BenchmarkContainer[] bigs = new BenchmarkContainer[howMany]; for (int i = 0; i < howMany; i++) { int smallSize = p.sample(); int bigSize = smallSize * param; short[] small = smallType == 0 ? generateUniform(ud, smallSize) : generateClustered(cd, smallSize); short[] big = bigType == 0 ? generateUniform(ud, bigSize) : generateClustered(cd, bigSize); smalls[i] = new BenchmarkContainer(small); bigs[i] = new BenchmarkContainer(big); } return new BenchmarkData(smalls, bigs); }