Example usage for java.util Random nextDouble

List of usage examples for java.util Random nextDouble

Introduction

In this page you can find the example usage for java.util Random nextDouble.

Prototype

public double nextDouble() 

Source Link

Document

Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.

Usage

From source file:com.mapr.synth.drive.Producer.java

@Override
public void run() {
    Random rand = new Random(3);
    GeoPoint start = new GeoPoint((rand.nextDouble() - 0.5) * Math.PI / 2, rand.nextDouble() * Math.PI * 2);
    final Vector3D east = start.east();
    final Vector3D north = start.north(east);

    GeoPoint end = new GeoPoint(start.as3D().add(east.scalarMultiply(-12.0 / Constants.EARTH_RADIUS_KM))
            .add(north.scalarMultiply(7.0 / Constants.EARTH_RADIUS_KM)));

    Vector3D zz = project(east, north, end.as3D());
    System.out.printf("==> %.2f %.2f\n", zz.getX(), zz.getY());

    while (true) {
        double t = 0;
        final Car car = new Car();

        System.out.printf("%.2f\n", start.distance(end));
        car.driveTo(rand, t, start, end, new Car.Callback() {
            @Override//from w w w.j  av  a2s.  c om
            void call(double t, Engine eng, GeoPoint position) {
                final Vector3D here = project(east, north, position.as3D());
                try {
                    output.put(new Trails.State(new Engine(eng), here));
                } catch (InterruptedException e) {
                    throw new RuntimeException("Interrupted", e);
                }
            }
        });
    }
}

From source file:org.owasp.benchmark.testcode.BenchmarkTest01699.java

double getNextNumber(java.util.Random generator) {
    return generator.nextDouble();
}

From source file:edu.umass.cs.gigapaxos.testing.TESTPaxosConfig.java

/**
 * Sets consistent, random groups starting with the same random seed.
 * /*from   w  w  w  . j  av a  2  s  .c  om*/
 * @param numGroups
 */
public static void setRandomGroups(int numGroups) {
    // if(!getCleanDB()) return;
    Random r = new Random(RANDOM_SEED);
    for (int i = 0; i < Math.min(Config.getGlobalInt(TC.PRE_CONFIGURED_GROUPS), numGroups); i++) {
        groups.put(Config.getGlobalString(TC.TEST_GUID_PREFIX) + i, defaultGroup);
        if (i == 0)
            continue;// first group is always default group
        TreeSet<Integer> members = new TreeSet<Integer>();
        for (int id : TESTPaxosConfig.getNodes()) {
            if (r.nextDouble() > Config.getGlobalDouble(TC.NODE_INCLUSION_PROB)) {
                members.add(id);
            }
        }
        TESTPaxosConfig.setGroup(TESTPaxosConfig.getGroupName(i), members);
    }
}

From source file:de.terministic.serein.core.genome.recombination.UniformCrossover.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override/*  w w  w  .  j a v a2 s  .com*/
G recombine(G g1, G g2, Random random) {
    List result = new ArrayList();
    for (int i = 0; i < g1.size(); i++) {
        if (random.nextDouble() < dominance) {
            result.add(g1.getGenes().get(i));
        } else {
            result.add(g2.getGenes().get(i));
        }
    }
    return (G) g1.createInstance(result);
}

From source file:org.orcid.core.manager.impl.OrcidGenerationManagerImpl.java

private long getRandomNumber() {
    Random random = new Random();
    // XXX Need to test edge cases
    return (long) (ORCID_BASE_MIN + (random.nextDouble() * (ORCID_BASE_MAX - ORCID_BASE_MIN + 1)));
}

From source file:br.upe.ecomp.doss.algorithm.pso.PSOParticle.java

/**
 * Updates the current velocity of the particle.
 * //from  w  w w . ja  va  2  s .com
 * @param inertialWeight The inertia weight
 * @param bestParticleNeighborhood The best particle in the neighborhood
 * @param c1 The cognitive component
 * @param c2 The social component
 * @param problem The problem that we are trying to solve.
 */
public void updateVelocity(double inertialWeight, double[] bestParticleNeighborhood, double c1, double c2,
        Problem problem) {
    Random random = new Random();
    double r1 = random.nextDouble();
    double r2 = random.nextDouble();

    double[] pBest = getBestPosition();
    for (int i = 0; i < getDimensions(); i++) {
        velocity[i] = inertialWeight * velocity[i] + c1 * r1 * (pBest[i] - getCurrentPosition()[i])
                + c2 * r2 * (bestParticleNeighborhood[i] - getCurrentPosition()[i]);

        double maxVelocity = (problem.getUpperBound(i) - problem.getLowerBound(i)) * velocityClampingPercent;
        velocity[i] = (velocity[i] > maxVelocity) ? maxVelocity : velocity[i];
        velocity[i] = (velocity[i] < -maxVelocity) ? -maxVelocity : velocity[i];
    }
}

From source file:br.upe.ecomp.doss.algorithm.chargedpso.ChargedPSOParticle.java

/**
 * Updates the current velocity of the particle.
 * //w  w w.ja v a2 s .  c o  m
 * @param inertialWeight The inertia weight
 * @param bestParticleNeighborhood The best particle in the neighborhood
 * @param c1 The cognitive component
 * @param c2 The social component
 */
public void updateVelocity(double inertialWeight, double[] bestParticleNeighborhood, double c1, double c2,
        double[] acceleration) {

    Random random = new Random();
    double r1 = random.nextDouble();
    double r2 = random.nextDouble();
    double[] velocity = getVelocity();

    double[] pBest = getBestPosition();
    for (int i = 0; i < getDimensions(); i++) {
        velocity[i] = inertialWeight * velocity[i] + c1 * r1 * (pBest[i] - getCurrentPosition()[i])
                + c2 * r2 * (bestParticleNeighborhood[i] - getCurrentPosition()[i]) + acceleration[i];
    }
    setVelocity(velocity);
}

From source file:com.facebook.presto.operator.aggregation.TestBootstrappedAggregation.java

@Test
public void testSum() throws Exception {
    int sum = 1_000;
    PageBuilder builder = new PageBuilder(ImmutableList.of(BIGINT, BIGINT));
    Random rand = new Random(0);
    for (int i = 0; i < sum; i++) {
        if (rand.nextDouble() < 0.5) {
            builder.getBlockBuilder(0).appendLong(1);
            builder.getBlockBuilder(1).appendLong(2);
        }/*from  w  w w  .  jav  a2  s. c  o  m*/
    }

    AggregationFunction function = new DeterministicBootstrappedAggregation(createTestingBlockEncodingManager(),
            LONG_SUM);

    assertApproximateAggregation(function, 1, 0.99, (double) sum, builder.build());
}

From source file:ro.hasna.ts.math.ml.distance.SaxEuclideanDistanceTest.java

@Test
public void testEquality() throws Exception {
    int n = 128;//from  ww  w. j  a  v  a2s .  c o  m
    double a[] = new double[n];
    double b[] = new double[n];
    Random random = new Random();
    for (int i = 0; i < n; i++) {
        a[i] = i;
        b[i] = 100 + i + random.nextDouble();
    }

    double result = distance.compute(sax.transform(a), sax.transform(b));

    Assert.assertEquals(0, result, TimeSeriesPrecision.EPSILON);
}

From source file:ar.org.neuroph.core.Weight.java

public void randomize(Random generator) {
    this.value = generator.nextDouble();
}