Instance methods operate on a user supplied uniform random number generator; they are unsynchronized.
@author wolfgang.hoschek@cern.ch @version 1.0, 09/24/99
783784785786787788789790791792793
Item item; if(id != -1) item = subjectAgent.removeItem(id); else{ item = new Uniform(this.getNextID(), this); this.addItem(item); } agent.addItem(item); System.out.println(
737738739740741742743744745746747
guard.addItems(items); } } // add the uniform: Uniform clothes = new Uniform(map.getNextID(), map); guard.addItem(clothes); map.addItem(clothes); if(isStunned) guard.daze();
154155156157158159160161162163164165166
// Simply make a list (0,1,..N-1) and randomize it, seeded with "p". // Note that this is perhaps not what you want... for (int i = N; --i >= 0;) { permutation[i] = i; } Uniform gen = new Uniform(new MersenneTwister((int) p)); for (int i = 0; i < N - 1; i++) { int random = gen.nextIntFromTo(i, N - 1); //swap(i, random) int tmp = permutation[random]; permutation[random] = permutation[i]; permutation[i] = tmp;
5354555657585960
*/ public WeightedRandomSampler(int weight, RandomEngine randomGenerator) { if (randomGenerator == null) { randomGenerator = org.apache.mahout.math.jet.random.AbstractDistribution.makeDefaultGenerator(); } this.generator = new Uniform(randomGenerator); setWeight(weight); }
5859606162636465
*/ public WeightedRandomSampler(int weight, Random randomGenerator) { if (randomGenerator == null) { randomGenerator = RandomUtils.getRandom(); } this.generator = new Uniform(randomGenerator); setWeight(weight); }
89909192939495969798
@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); } }
118119120121122123124125126127128129130131132133134
// 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; }
285286287288289290291292
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); } }
7475767778798081828384
@Test public void testUniform() { RandomWrapper gen = RandomUtils.getRandom(); for (int i = 0; i < 5; i++) { runTest(new Uniform(0, 1, gen), 100, // new double[]{0.0001, 0.001, 0.01, 0.1, 0.5, 0.9, 0.99, 0.999, 0.9999}, new double[]{0.001, 0.01, 0.1, 0.5, 0.9, 0.99, 0.999}, "uniform", true); } }
104105106107108109110111112113114115116117118119120
// 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 RandomWrapper 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; }