Can Random.nextgussian () select values ​​from a distribution with different mean and standard deviation?

This is a combined Java and basic math question. The documentation from Random.nextGaussian () indicates that it displays from a normal distribution with a mean of 0 and a standard deviation of 1. What if I would like to try from a normal distribution with a different mean and variance?

+11
source share
1 answer

Short answer

Random r = new Random();
double mySample = r.nextGaussian()*desiredStandardDeviation+desiredMean;

For example, this answer is given below: http://www.javamex.com/tutorials/random_numbers/gaussian_distribution_2.shtml

, , , , , . 0, 1; , z- (https://en.wikipedia.org/wiki/Standard_score). " z ". z = (x-mean)/stdev, z = x. z , stdev, ?

z * stdev + mean = x ', z = x, x' .

+30

Source: https://habr.com/ru/post/1652463/


All Articles