Refine search
@Override public int nextInt() { return random.nextInt(); }
/** Generate a random scalar with null mean and unit standard deviation. * <p>The number generated is uniformly distributed between -&sqrt;(3) * and +&sqrt;(3).</p> * @return a random scalar with null mean and unit standard deviation */ public double nextNormalizedDouble() { return SQRT3 * (2 * generator.nextDouble() - 1.0); }
/** * {@inheritDoc} */ public synchronized long nextLong() { return wrapped.nextLong(); }
double omega = -FastMath.log(generator.nextDouble()); double phi = FastMath.PI * (generator.nextDouble() - 0.5); return FastMath.sqrt(2d * omega) * FastMath.sin(phi);
final double u = random.nextDouble(); final double bGS = 1 + shape / FastMath.E; final double p = bGS * u; final double x = FastMath.pow(p, 1 / shape); final double u2 = random.nextDouble(); if (u2 > FastMath.exp(-x)) { final double x = -1 * FastMath.log((bGS - p) / shape); final double u2 = random.nextDouble(); if (u2 > FastMath.pow(x, shape - 1)) { final double x = random.nextGaussian(); final double v = (1 + c * x) * (1 + c * x) * (1 + c * x); final double u = random.nextDouble();
final double b) { final double alpha = a + b; final double beta = FastMath.sqrt((alpha - 2.) / (2. * a * b - alpha)); final double gamma = a + 1. / beta; double t; do { final double u1 = random.nextDouble(); final double u2 = random.nextDouble(); final double v = beta * (FastMath.log(u1) - FastMath.log1p(-u1)); w = a * FastMath.exp(v); final double z = u1 * u1 * u2;
final double pivot = 40.0d; if (meanPoisson < pivot) { double p = FastMath.exp(-meanPoisson); long n = 0; double r = 1.0d; rnd = random.nextDouble(); r *= rnd; if (r >= p) { final double lambda = FastMath.floor(meanPoisson); final double lambdaFractional = meanPoisson - lambda; final double logLambda = FastMath.log(lambda); final double logLambdaFactorial = CombinatoricsUtils.factorialLog((int) lambda); final long y2 = lambdaFractional < Double.MIN_VALUE ? 0 : nextPoisson(lambdaFractional); double qa = 0; for (;;) { final double u = random.nextDouble(); if (u <= p1) { final double n = random.nextGaussian(); x = n * FastMath.sqrt(lambda + halfDelta) - 0.5d; if (x > delta || x < -lambda) {
@Override public RandomGenerator newInstance() { stateCheck(); return new MersenneTwister(masterRandomGenerator.nextLong()); }
/** * Returns an instance of a random number generator, which can be used locally, e.g. in threads. */ public static RandomGenerator getLocalGenerator() { return new MersenneTwister(rg.nextInt()); } }
/** {@inheritDoc} */ @Override public double sample() { final double n = random.nextDouble(); return scale / FastMath.pow(n, 1 / shape); } }
@Override public Pair<String,String> generate(int id, RandomGenerator random) { return new Pair<>(Integer.toString(id), id + "," + random.nextInt(100) + ',' + random.nextBoolean() + ',' + random.nextGaussian()); }
RandomWrapper() { random = new MersenneTwister(); random.setSeed(System.currentTimeMillis() + System.identityHashCode(random)); }
/** {@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} */ public double[] nextVector() { final double[] v = new double[dimension]; // See http://mathworld.wolfram.com/SpherePointPicking.html for example. // Pick a point by choosing a standard Gaussian for each element, and then // normalizing to unit length. double normSq = 0; for (int i = 0; i < dimension; i++) { final double comp = rand.nextGaussian(); v[i] = comp; normSq += comp * comp; } final double f = 1 / FastMath.sqrt(normSq); for (int i = 0; i < dimension; i++) { v[i] *= f; } return v; } }
/** {@inheritDoc} */ @Override public double sample() { final double n = random.nextGaussian(); return FastMath.exp(scale + shape * n); } }
@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); } }
@Override public boolean nextBoolean() { return random.nextBoolean(); }
/** * {@inheritDoc} */ public synchronized float nextFloat() { return wrapped.nextFloat(); }