下面列出了java.util.concurrent.ThreadLocalRandom#nextGaussian ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
/**
* 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;
}
}
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;
}
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));
}
@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;
}