Example usage for java.util Random nextGaussian

List of usage examples for java.util Random nextGaussian

Introduction

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

Prototype

public synchronized double nextGaussian() 

Source Link

Document

Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.

Usage

From source file:Main.java

public static void main(String[] args) {
    Random r = new Random();

    // generate some random boolean values
    boolean[] booleans = new boolean[10];
    for (int i = 0; i < booleans.length; i++) {
        booleans[i] = r.nextBoolean();//from w ww  .  j a v  a2  s  .co  m
    }

    for (boolean b : booleans) {
        System.out.print(b + ", ");
    }

    // generate a uniformly distributed int random numbers
    int[] integers = new int[10];
    for (int i = 0; i < integers.length; i++) {
        integers[i] = r.nextInt();
    }

    for (int i : integers) {
        System.out.print(i + ", ");
    }

    // generate a uniformly distributed float random numbers
    float[] floats = new float[10];
    for (int i = 0; i < floats.length; i++) {
        floats[i] = r.nextFloat();
    }

    for (float f : floats) {
        System.out.print(f + ", ");
    }

    // generate a Gaussian normally distributed random numbers
    double[] gaussians = new double[10];
    for (int i = 0; i < gaussians.length; i++) {
        gaussians[i] = r.nextGaussian();
    }

    for (double d : gaussians) {
        System.out.print(d + ", ");
    }
}

From source file:org.jfree.chart.demo.HistogramDemo1.java

private static IntervalXYDataset createDataset() {
    HistogramDataset histogramdataset = new HistogramDataset();
    double ad[] = new double[1000];
    Random random = new Random(0xbc614eL);
    for (int i = 0; i < 1000; i++)
        ad[i] = random.nextGaussian() + 5D;

    histogramdataset.addSeries("H1", ad, 100, 2D, 8D);
    ad = new double[1000];
    for (int j = 0; j < 1000; j++)
        ad[j] = random.nextGaussian() + 7D;

    histogramdataset.addSeries("H2", ad, 100, 4D, 10D);
    return histogramdataset;
}

From source file:com.jaxzin.iraf.demo.Main.java

private static double[] createNormalDist(final int count, final double offset) {
    final double[] data = new double[count];
    final Random rand = new Random();
    for (int i = 0; i < data.length; i++) {
        data[i] = rand.nextGaussian() + offset;
    }//from   w  w  w .j  a v  a  2 s.  co  m
    return data;
}

From source file:io.druid.query.aggregation.datasketches.tuple.GenerateTestData.java

private static void generateBucketTestData() throws Exception {
    double meanTest = 10;
    double meanControl = 10.2;
    Path path = FileSystems.getDefault().getPath("bucket_test_data.tsv");
    try (BufferedWriter out = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
        Random rand = new Random();
        for (int i = 0; i < 1000; i++) {
            writeBucketTestRecord(out, "test", i, rand.nextGaussian() + meanTest);
            writeBucketTestRecord(out, "control", i, rand.nextGaussian() + meanControl);
        }/*from www  .ja va  2  s .  c om*/
    }
}

From source file:carrental.beans.billing.BillingBean.java

/**
 * @param servicePrice The standardized servicePrice is used as the mean for the randomized cost-calculation
 *//*from   w w  w .j av  a 2 s.com*/
private static BigDecimal simulateRepairCosts(double servicePrice) {
    Random randomGenerator = new Random();
    Double r = randomGenerator.nextGaussian() * 90 + servicePrice; //z*SD + mu
    return new BigDecimal(r).setScale(2, RoundingMode.FLOOR);
}

From source file:org.apache.druid.query.aggregation.datasketches.tuple.GenerateTestData.java

private static void generateBucketTestData() throws Exception {
    double meanTest = 10;
    double meanControl = 10.2;
    Path path = FileSystems.getDefault().getPath("bucket_test_data.tsv");
    try (BufferedWriter out = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
        Random rand = ThreadLocalRandom.current();
        for (int i = 0; i < 1000; i++) {
            writeBucketTestRecord(out, "test", i, rand.nextGaussian() + meanTest);
            writeBucketTestRecord(out, "control", i, rand.nextGaussian() + meanControl);
        }//from w  ww .j  ava2s . co  m
    }
}

From source file:com.opengamma.examples.historical.SimulatedHistoricalDataGenerator.java

private static double wiggleValue(final Random random, final double value) {
    double result = value + (random.nextGaussian() * (value * SCALING_FACTOR));
    //s_logger.warn("wiggleValue = {}", result);
    return result;
}

From source file:net.sf.mzmine.chartbasics.gui.javafx.demo.FXCategoryChartGestureDemo.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return the dataset./*from  ww w.  ja  va  2 s  . c o  m*/
 */
private static CategoryDataset createDataset() {
    DefaultCategoryDataset data = new DefaultCategoryDataset();
    Random r = new Random(System.currentTimeMillis());
    for (int i = 0; i < 3; i++) {
        for (int t = 0; t < 2; t++) {

            for (int x = 0; x < 100; x++) {
                double v = r.nextGaussian() * (i + 1);
                data.addValue(v, "series" + i, "type" + t);
            }
        }
    }
    return data;
}

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

/**
 * Get random value//  ww  w.j a va2s  .com
 *
 * @return Random value
 */
public static double randn() {
    Random r = new Random();
    return r.nextGaussian();
}

From source file:net.sf.mzmine.chartbasics.gui.javafx.demo.FXChartGestureDemo.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return the dataset./*from  w ww .j  av  a  2 s  . c o m*/
 */
private static XYDataset createDataset() {
    XYSeriesCollection data = new XYSeriesCollection();

    Random r = new Random(System.currentTimeMillis());

    for (int i = 0; i < 3; i++) {
        XYSeries s = new XYSeries("Series" + i);
        for (int x = 0; x < 100; x++) {
            double v = r.nextGaussian() * (i + 1);
            s.add(x, v);
        }
        data.addSeries(s);
    }
    return data;
}