NormalPrng
edu.rit.numeric

Class NormalPrng



  • public class NormalPrngextends 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
    y2 = sqrt(−2 ln x1) sin 2πx2
    And (μ + σy1) and (μ + σy2) are drawn from a normal distribution with mean μ and standard deviation σ.

    Note: 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.
    • 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:
        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:
        NullPointerException - (unchecked exception) Thrown if theUniformPrng is null.
    • Method Detail

      • next

        public double next()
        Returns the next random number.
        Specified by:
        next in class DoublePrng
        Returns:
        Random number.

SCaVis 2.2 © jWork.ORG