Java Code Examples for java.util.concurrent.ThreadLocalRandom#nextGaussian()

The following examples show how to use java.util.concurrent.ThreadLocalRandom#nextGaussian() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void run(SourceContext<MonitoringEvent> sourceContext) throws Exception {
    while (running) {
        MonitoringEvent monitoringEvent;

        final ThreadLocalRandom random = ThreadLocalRandom.current();

        if (shard > 0) {
            int rackId = random.nextInt(shard) + offset;

            if (random.nextDouble() >= temperatureRatio) {
                double power = random.nextGaussian() * powerStd + powerMean;
                monitoringEvent = new PowerEvent(rackId, power);
            } else {
                double temperature = random.nextGaussian() * temperatureStd + temperatureMean;
                monitoringEvent = new TemperatureEvent(rackId, temperature);
            }


            sourceContext.collect(monitoringEvent);
        }

        Thread.sleep(pause);
    }
}
 
Example 2
/**
 * Fills a subset of the null
 *
 * @param geneChi2SumNull vector to fill will null chi2 values
 * @param eigenValues
 * @param randomChi2 reference distribution
 * @param start zero based count
 * @param stop zero based count, so must be < nrPermutation @return @param
 * rnd @pa r am eigenValuesLengt h
 */
public static void runPermutationsUsingEigenValues(final double[] geneChi2SumNull, final double[] eigenValues, double[] randomChi2, final int start, final int stop, final ThreadLocalRandom rnd, final int eigenValuesLength) {

	final int randomChi2Size = randomChi2.length;

	//LOGGER.debug("start: " + start + " stop: " + stop);
	int i = start;
	for (int perm = start; perm < stop; perm++) {
		double weightedChi2Perm = 0;
		for (int g = 0; g < eigenValuesLength; g++) {

			if (i < randomChi2Size) {
				weightedChi2Perm += eigenValues[g] * randomChi2[i++];
			} else {
				double randomZ = rnd.nextGaussian();
				weightedChi2Perm += eigenValues[g] * (randomZ * randomZ);
			}

		}
		geneChi2SumNull[perm] = weightedChi2Perm;
	}

}
 
Example 3
private int generatePlanetDiameter(int position) {
  ThreadLocalRandom random = ThreadLocalRandom.current();
  double x = Math.abs(8 - position);
  double mean = 200.0 - 10.0 * x;
  double sd = 60.0 - 5.0 * x;
  double numFields = mean + sd * random.nextGaussian();
  numFields = Math.max(numFields, 42.0);
  return (int) (Math.sqrt(numFields) * 100.0) * 10;
}
 
Example 4
private int generateTemperature(int position) {
  ThreadLocalRandom random = ThreadLocalRandom.current();
  double x = 8 - position;
  double mean = 30.0 + 1.75 * Math.signum(x) * x * x;
  int temperature = (int) (mean + 10.0 * random.nextGaussian());
  return Math.max(-60, Math.min(120, temperature));
}
 
Example 5
@Override
public double[] call() throws Exception {
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    double[] geneChi2SumNull = new double[nrPermsThisTask];
    for (int perm=0; perm<nrPermsThisTask; perm++) {
        double weightedChi2Perm = 0;
        for (int g=0; g<eigenValues.length; g++) {
            double randomZ = rnd.nextGaussian();
            weightedChi2Perm+=eigenValues[g] * randomZ * randomZ;
        }
        geneChi2SumNull[perm]=weightedChi2Perm;
    } 
    return geneChi2SumNull;
}