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:edu.jhuapl.graphs.jfreechart.TimeSeriesEffectsTest.java

private static double getNextRandomValue(Random r) {
    // we have a 90% chance of something in 0-10, and a 10% chance of something in 10-20
    if (r.nextDouble() <= .9) {
        return 10 * r.nextDouble();
    } else {//  w  ww .j  a v  a  2s . c  o  m
        return 10 + 10 * r.nextDouble();
    }
}

From source file:play.sax.main.Main.java

private static TimeSeries generateRandomTimeSeries(final int noOfEntries) {

    final TimeSeries series = new TimeSeries();
    RandomDataGenerator randomData = new RandomDataGenerator();
    Random rand = new Random();

    for (int i = 0; i < noOfEntries; i++) {
        final Long time = randomData.nextLong(0, 20000);
        final Double value = DATA_LOWER_BOUND + DATA_RANGE * rand.nextDouble();
        final TimeSeriesEntry entry = new TimeSeriesEntry(time, value);

        series.addTimeSeriesEntry(entry);
    }//ww w  .j ava2s . c o  m
    return series;
}

From source file:de.terministic.serein.core.genome.DoubleGenome.java

static public DoubleGenome createRandomDoubleGenome(int size, Random random) {
    List<Double> genes = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        genes.add(random.nextDouble());
    }/*from w  w w  .java2s .  co m*/
    return new DoubleGenome(genes);
}

From source file:org.deeplearning4j.examples.multigpu.rnn.LSTMCharModellingExample.java

/** Given a probability distribution over discrete classes, sample from the distribution
 * and return the generated class index.
 * @param distribution Probability distribution over classes. Must sum to 1.0
 *///from   ww w.j  a va  2 s .c  o m
public static int sampleFromDistribution(double[] distribution, Random rng) {
    double d = rng.nextDouble();
    double sum = 0.0;
    for (int i = 0; i < distribution.length; i++) {
        sum += distribution[i];
        if (d <= sum)
            return i;
    }
    //Should never happen if distribution is a valid probability distribution
    throw new IllegalArgumentException("Distribution is invalid? d=" + d + ", sum=" + sum);
}

From source file:es.uvigo.darwin.jmodeltest.io.RFHistogram.java

public static JFreeChart buildRandomHistogram() {
    Random generator = new Random();
    double[] value = new double[100];
    for (int i = 1; i < 100; i++) {
        value[i] = generator.nextDouble();
    }//from  ww w.  j a v  a2  s.  com
    int number = 10;
    String plotTitle = "Histogram";
    String xaxis = "number";
    String yaxis = "value";
    JFreeChart chart = buildHistogram(value, number, plotTitle, xaxis, yaxis);
    return chart;
}

From source file:org.meteoinfo.math.RandomUtil.java

/**
 * Get random value/*from w  ww. jav a 2  s.c  o  m*/
 *
 * @return Random value
 */
public static double rand() {
    Random r = new Random();
    return r.nextDouble();
}

From source file:cz.cuni.mff.d3s.spl.example.newton.app.Main.java

private static double[] generateCoefficients(Random random) {
    int n = random.nextInt(MAX_POLYNOM_DEGREE) + 1;
    double[] result = new double[n];
    for (int i = 0; i < n; i++) {
        double coeff = random.nextDouble() - 0.5;
        result[i] = coeff * COEFFICIENT_MULTIPLIER;
    }//from www .  j  ava2  s.c  o  m
    return result;
}

From source file:com.oculusinfo.ml.spark.unsupervised.TestKMeans.java

public static void genTestData(int k) {
    PrintWriter writer;//  ww  w.ja v  a2  s . c  om
    try {
        writer = new PrintWriter("test.txt", "UTF-8");

        // each class size is equal 
        int classSize = 1000000 / k;

        double stdDev = 30.0;

        // generate k classes of data points using a normal distribution with random means and fixed std deviation
        for (int i = 0; i < k; i++) {
            Random rnd = new Random();

            double meanX = rnd.nextDouble() * 400.0;
            double meanY = rnd.nextDouble() * 400.0;

            // randomly generate a dataset of x, y points
            for (int j = 0; j < classSize; j++) {
                double x = rnd.nextGaussian() * stdDev + meanX;
                double y = rnd.nextGaussian() * stdDev + meanY;

                writer.println(x + "," + y);
            }
        }
        writer.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:ubic.BAMSandAllen.FocusedAnalysis.TestConnectivityRobustness.java

public static void main2() throws Exception {
    Direction direction = AnalyzeBAMSandAllenGenes.Direction.INCOMING;
    boolean makeVirtualRegions = true;

    boolean squareMatrix = false;
    boolean logDistance = true;
    boolean slow = false;
    RegressMatrix regressType = RegressMatrix.BOTH;
    boolean useVirtual = true;
    boolean removeNonExp = true;
    boolean run = false;

    List<Double> resultCor = new LinkedList<Double>();
    List<Double> resultSig = new LinkedList<Double>();

    int seed = 1;
    int splits = 2;

    for (int i = 0; i < splits; i++) {
        ConnectivityAndAllenExpressionMatrixPair pair = ExpressionMatrixPairFactory.connectivityPartial(
                direction, slow, regressType, useVirtual, removeNonExp, logDistance, squareMatrix, run);

        pair.removeZeroConnectionRows();

        //            String filename = "/grp/java/workspace/BAMSandAllen/data/rankedGenes/near final ammon/";
        //             filename += "LOOGenesInOrder.in.partialcon.ammon.txt.452.0.01985.topGenes.txt";
        //            //filename += "LOOGenesInOrder.out.partialcon.ammon.txt.374.0.016424.topGenes.txt";
        //            RankedGeneListLoader aLook = new RankedGeneListLoader( filename );
        //            pair.setMatrixBDataRows( aLook.getLines() );

        // remove rows
        List<String> connectionRows = pair.getMatrixA().getRowNames();
        List<String> removeRows = new LinkedList<String>();
        Random r = new Random(seed);
        for (String region : connectionRows) {
            int remove = (int) (r.nextDouble() * splits);
            if (remove != i) {
                removeRows.add(region);/*from  www  .j av  a 2  s. com*/
            }
        }
        pair.removeMatrixADataRows(removeRows);
        pair.printConnectionInfo();
        pair.printDimensions();
        pair.run();
        double correlation = pair.getCorrelation();
        log.info(correlation);
        resultCor.add(correlation);
        resultSig.add(pair.test(1000));
    }
    log.info("Correlations:" + resultCor);
    log.info("Pvalues:" + resultSig);
}

From source file:edu.umich.eecs.rtcl.lp_doctor.utilities.MathTools.java

public static LatLng getFakeLocation(LatLng currentLoc, int trackLevel) {
    double radius = getRadius(trackLevel);
    double privacyLevel = Math.log(4);
    Random rand = new Random();//need good source of randomness
    double theta = rand.nextDouble() * 360;
    double p = rand.nextDouble();
    double eps = privacyLevel / radius; //some thing around 1000 m

    double lam = LambertW.branchNeg1((p - 1) / Math.exp(1));
    double r = (-1 / eps) * (lam + 1);

    return Util.calculateDerivedPosition(currentLoc, r, theta);

}