Question

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!

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top