문제

first of all, i'd like you to know that i really lack knowledge/suck at math. Right now, there is a code algorithm that states the use of a Gaussian random function. I honestly don't know a thing about gaussian random function. All i know in java is math.random().

The equation i would like into the code is in the form:

  rand = n(m,v);

where n(m,v) represents the gaussian random function with mean (m) and variance (v). What is the equivalent for this in java? Thanks!

도움이 되었습니까?

해결책

The Random class supplies the nextGaussian method, a random Gaussian with a mean of 0 and a standard deviation of 1.

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.

Try

rand = rnd.nextGaussian() * Math.sqrt(v) + m;

The Math.sqrt is in there to convert a variance to standard deviation.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top