Class NormalPrng
- java.lang.Object
-
- edu.rit.numeric.DoublePrng
-
- edu.rit.numeric.NormalPrng
-
public class NormalPrng extends DoublePrng
Class NormalPrng provides a pseudorandom number generator (PRNG) that generates random numbers with a normal distribution.Every two calls of the next() method result in two calls of the underlying uniform PRNG's nextDouble() method. More precisely, the first of a pair of next() calls does two nextDouble() calls, the second of a pair of next() calls does not call nextDouble().
Class NormalPrng uses the Box-Muller method to generate a standard normal distribution. Let x1 and x2 be drawn from a uniform distribution between 0 and 1. Then y1 and y2, defined as follows, are drawn from a standard normal distribution.
y1 = sqrt(−2 ln x1) cos 2πx2 And (μ + σy1) and (μ + σy2) are drawn from a normal distribution with mean μ and standard deviation σ.
y2 = sqrt(−2 ln x1) sin 2πx2Note: While slower than other techniques, this technique does a fixed number of nextDouble() calls to generate each normally distributed random number. This behavior is important when parallel programs generate random numbers.
-
-
Constructor Summary
Constructors Constructor and Description NormalPrng(Random theUniformPrng)Construct a new standard normal PRNG.NormalPrng(Random theUniformPrng, double theMean, double theStdev)Construct a new normal PRNG with the given mean and standard deviation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description doublenext()Returns the next random number.
-
-
-
Constructor Detail
-
NormalPrng
public NormalPrng(Random theUniformPrng)
Construct a new standard normal PRNG. The mean is 0 and the standard deviation is 1.- Parameters:
theUniformPrng- The underlying uniform PRNG.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theUniformPrng is null.
-
NormalPrng
public NormalPrng(Random theUniformPrng, double theMean, double theStdev)
Construct a new normal PRNG with the given mean and standard deviation.- Parameters:
theUniformPrng- The underlying uniform PRNG.theMean- Mean of the normal distribution.theStdev- Standard deviation of the normal distribution.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theUniformPrng is null.
-
-
Method Detail
-
next
public double next()
Returns the next random number.- Specified by:
nextin classDoublePrng- Returns:
- Random number.
-
-
DMelt 3.0 © DataMelt by jWork.ORG