@Override AbstractDistribution create(Random random) { return new Uniform(0, 1, random); } },
return from + (long) nextDoubleFromTo(0.0, to - from + 1); return from + (long) nextDoubleFromTo(0.0, diff); if (to == Long.MAX_VALUE) { int i1 = nextIntFromTo(Integer.MIN_VALUE, Integer.MAX_VALUE); int i2 = nextIntFromTo(Integer.MIN_VALUE, Integer.MAX_VALUE); return ((i1 & 0xFFFFFFFFL) << 32) | (i2 & 0xFFFFFFFFL); random = Math.round(nextDoubleFromTo(Long.MIN_VALUE, to + 1)); if (random > to) { random = Long.MIN_VALUE; random = Math.round(nextDoubleFromTo(from - 1, to)); if (random < from) { random = to;
/** * Returns a uniformly distributed random number in the open interval <tt>(min,max)</tt> (excluding <tt>min</tt> and * <tt>max</tt>). */ @Override public double nextDouble() { return min + (max - min) * randomDouble(); }
/** Constructs a uniform distribution with the given minimum and maximum. */ public Uniform(double min, double max, Random randomGenerator) { setRandomGenerator(randomGenerator); setState(min, max); }
Uniform u = new Uniform(gen); for (int j = 0; j < totalItems; j++) { prob[j] = u.nextDouble(); int reward = u.nextDouble() < prob[k] ? 1 : 0; bandit.get(m).train(k, reward);
/** Sets the internal state. */ public void setState(double min, double max) { if (max < min) { setState(max, min); return; } this.min = min; this.max = max; }
/** * Returns a uniformly distributed random number in the open interval <tt>(from,to)</tt> (excluding <tt>from</tt> and * <tt>to</tt>). Pre conditions: <tt>from <= to</tt>. */ public float nextFloatFromTo(float from, float to) { return (float) nextDoubleFromTo(from, to); }
/** Constructs a uniform distribution with the given minimum and maximum. */ public Uniform(double min, double max, Random randomGenerator) { setRandomGenerator(randomGenerator); setState(min, max); }
/** Sets the internal state. */ public void setState(double min, double max) { if (max < min) { setState(max, min); return; } this.min = min; this.max = max; }
/** * Returns a uniformly distributed random number in the open interval <tt>(from,to)</tt> (excluding <tt>from</tt> and * <tt>to</tt>). Pre conditions: <tt>from <= to</tt>. */ public float nextFloatFromTo(float from, float to) { return (float) nextDoubleFromTo(from, to); }
@Test public void testUniform() { Random gen = RandomUtils.getRandom(); for (int i = 0; i < repeats(); i++) { runTest(new Uniform(0, 1, gen), 100, new double[]{0.001, 0.01, 0.1, 0.5, 0.9, 0.99, 0.999}, "uniform", true, gen); } }
/** * Returns a uniformly distributed random number in the closed interval * <tt>[from,to]</tt> (including <tt>from</tt> * and <tt>to</tt>). Pre conditions: <tt>from <= to</tt>. */ public int nextIntFromTo(int from, int to) { return (int) (from + (long) ((1L + to - from) * randomDouble())); }
/** Constructs a uniform distribution with the given minimum and maximum. */ public Uniform(double min, double max, Random randomGenerator) { setRandomGenerator(randomGenerator); setState(min, max); }
return from + (long) nextDoubleFromTo(0.0, to - from + 1); return from + (long) nextDoubleFromTo(0.0, diff); if (to == Long.MAX_VALUE) { int i1 = nextIntFromTo(Integer.MIN_VALUE, Integer.MAX_VALUE); int i2 = nextIntFromTo(Integer.MIN_VALUE, Integer.MAX_VALUE); return ((i1 & 0xFFFFFFFFL) << 32) | (i2 & 0xFFFFFFFFL); random = Math.round(nextDoubleFromTo(Long.MIN_VALUE, to + 1)); if (random > to) { random = Long.MIN_VALUE; random = Math.round(nextDoubleFromTo(from - 1, to)); if (random < from) { random = to;
/** Sets the internal state. */ public void setState(double min, double max) { if (max < min) { setState(max, min); return; } this.min = min; this.max = max; }
/** * Returns a uniformly distributed random number in the open interval <tt>(from,to)</tt> (excluding <tt>from</tt> and * <tt>to</tt>). Pre conditions: <tt>from <= to</tt>. */ public float nextFloatFromTo(float from, float to) { return (float) nextDoubleFromTo(from, to); }
@Test public void compareToQDigest() { Random rand = RandomUtils.getRandom(); for (int i = 0; i < repeats(); i++) { compare(new Gamma(0.1, 0.1, rand), "gamma", 1L << 48, rand); compare(new Uniform(0, 1, rand), "uniform", 1L << 48, rand); } }
/** * Returns a uniformly distributed random number in the open interval <tt>(from,to)</tt> (excluding <tt>from</tt> and * <tt>to</tt>). Pre conditions: <tt>from <= to</tt>. */ public double nextDoubleFromTo(double from, double to) { return from + (to - from) * randomDouble(); }
return from + (long) nextDoubleFromTo(0.0, to - from + 1); return from + (long) nextDoubleFromTo(0.0, diff); if (to == Long.MAX_VALUE) { int i1 = nextIntFromTo(Integer.MIN_VALUE, Integer.MAX_VALUE); int i2 = nextIntFromTo(Integer.MIN_VALUE, Integer.MAX_VALUE); return ((i1 & 0xFFFFFFFFL) << 32) | (i2 & 0xFFFFFFFFL); random = Math.round(nextDoubleFromTo(Long.MIN_VALUE, to + 1)); if (random > to) { random = Long.MIN_VALUE; random = Math.round(nextDoubleFromTo(from - 1, to)); if (random < from) { random = to;
@Test public void testNarrowNormal() { // this mixture of a uniform and normal distribution has a very narrow peak which is centered // near the median. Our system should be scale invariant and work well regardless. final Random gen = RandomUtils.getRandom(); AbstractContinousDistribution mix = new AbstractContinousDistribution() { AbstractContinousDistribution normal = new Normal(0, 1e-5, gen); AbstractContinousDistribution uniform = new Uniform(-1, 1, gen); @Override public double nextDouble() { double x; if (gen.nextDouble() < 0.5) { x = uniform.nextDouble(); } else { x = normal.nextDouble(); } return x; } }; for (int i = 0; i < repeats(); i++) { runTest(mix, 100, new double[]{0.001, 0.01, 0.1, 0.3, 0.5, 0.7, 0.9, 0.99, 0.999}, "mixture", false, gen); } }