Example usage for org.apache.commons.math.random RandomGenerator nextDouble

List of usage examples for org.apache.commons.math.random RandomGenerator nextDouble

Introduction

In this page you can find the example usage for org.apache.commons.math.random RandomGenerator nextDouble.

Prototype

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:de.tud.kom.p2psim.impl.network.modular.st.latency.NormalDistributionLatency.java

/**
 * Precompute the delays.// ww  w .  j  a v  a2s  .co m
 * 
 * @param size
 *            The number of delays, which should be computed and stored in
 *            delays.
 */
private void createDelays(int size) {

    if (propagationMeanDelay < standardDeviation) {
        log.warn(
                "Bad Configuration! It is possible, that huge delays are negative and consequently this values will be set to the mean delay value.");
    }

    log.info("Create " + size + " precomputed delays");
    RandomGenerator randGen = Simulator.getRandom();
    delays = new Vector<Long>(size);
    for (int i = 0; i < size; i++) {
        long delay = 0;
        try {
            delay = (long) normalDistribution.inverseCumulativeProbability(randGen.nextDouble());
        } catch (MathException e) {
            log.error("MathException, check your parameteres for NormalDistributionLatency class...", e);
            throw new RuntimeException();
        }
        if (delay <= 0) {
            log.debug("Set delay to propagationMeanDelay (" + propagationMeanDelay
                    + ") because it has the value " + delay);
            delay = propagationMeanDelay;
        }
        delays.add(delay);
    }
    log.info("Finished, to create delays");
}

From source file:lfsom.visualization.clustering.LFSKMeans.java

/**
 * Calculate random centroids for each cluster.
 *///from w  w  w  .  j av  a2s . c  o m
private void initClustersRandomly() {
    RandomGenerator rg = new JDKRandomGenerator();
    // FIXME: this is for testing purposes only
    rg.setSeed(RANDOM_SEED);
    // for each cluster
    for (int clusterIndex = 0; clusterIndex < k; clusterIndex++) {
        // for each of its attributes
        double[] centroid = new double[numberOfAttributes];
        for (int attributeIndex = 0; attributeIndex < numberOfAttributes; attributeIndex++) {
            centroid[attributeIndex] = differences[attributeIndex] * rg.nextDouble()
                    + minValues[attributeIndex];
        }
        clusters[clusterIndex] = new LFSCluster(centroid);
    }
    System.out.println("initial centroids: ");
    // printCentroids();
}

From source file:org.peerfact.impl.network.modular.common.PingErToolkitTest.java

@Test
public void test1() {
    double avgRtt = 243.23d;
    double minRtt = 193.7d;
    double dVar = 10.78;

    long startTime = System.nanoTime();
    JitterParameter result = PingErToolkit.getJitterParameterFrom(avgRtt, minRtt, dVar);
    log.debug("Calculation lasted " + (System.nanoTime() - startTime) * 0.000001 + " ms");

    LognormalDist testDist = new LognormalDist(1, 0.6);

    RandomGenerator rand = new JDKRandomGenerator();

    for (int i = 0; i < 100; i++) {
        log.debug(testDist.inverseF(rand.nextDouble()));
    }//from  w  w  w  .jav  a  2 s.c  o m

    log.debug(result);
}