Class RandomNumberGen

  • All Implemented Interfaces:
    java.io.Serializable

    public class RandomNumberGen
    extends java.util.Random
    Algorithm that produces a random number (Gaussian or uniform) in a specific user/programmer defined range.
    Version:
    0.1 May 4, 1998
    Author:
    Matthew J. McAuliffe, Ph.D.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static long serialVersionUID
      Use serialVersionUID for interoperability.
    • Constructor Summary

      Constructors 
      Constructor Description
      RandomNumberGen()
      RandomNumberGen - constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static long factorial​(int number)
      Returns the factorial of a nonnegative integer.
      double genGaussianRandomNum​(double stRange, double endRange)
      Generates a Gaussian random number greater or equal to the stRange and less than or equal to the endRange.
      float genGaussianRandomNum​(float stRange, float endRange)
      Generates a Gaussian random number greater or equal to the stRange and less than or equal to the endRange.
      int genGaussianRandomNum​(int stRange, int endRange)
      Generates a Gaussian random number greater or equal to the stRange and less than or equal to the endRange.
      double genStandardGaussian()  
      double genUniformRandomNum​(double stRange, double endRange)
      Generates a uniform random number greater or equal to the stRange and less than or equal to the endRange.
      float genUniformRandomNum​(float stRange, float endRange)
      Generates a uniform random number greater or equal to the stRange and less than or equal to the endRange.
      int genUniformRandomNum​(int stRange, int endRange)
      Generates a uniform random number greater or equal to the stRange and less than or equal to the endRange.
      double[] poissDecay​(int nEvents, double mu, double gain, double offset)
      This code is derived from PoissDecay.cpp, PoissonDeviate, PoissonRecur, and RandomDeviate, code accompanying Data Reduction and Error Analysis for the Physical Sciences, Third Edition, by Philip R.
      • Methods inherited from class java.util.Random

        doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longs, next, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeed
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Use serialVersionUID for interoperability.
        See Also:
        Constant Field Values
    • Constructor Detail

      • RandomNumberGen

        public RandomNumberGen()
        RandomNumberGen - constructor.
    • Method Detail

      • factorial

        public static final long factorial​(int number)
        Returns the factorial of a nonnegative integer.
        Parameters:
        number - integer whose factorial is being returned
        Returns:
        number!
      • genGaussianRandomNum

        public final int genGaussianRandomNum​(int stRange,
                                              int endRange)
        Generates a Gaussian random number greater or equal to the stRange and less than or equal to the endRange.
        Parameters:
        stRange - the random number will be greater than or equal to this number
        endRange - the random number will be less than or equal to this number
        Returns:
        integer number in the range
      • genGaussianRandomNum

        public final float genGaussianRandomNum​(float stRange,
                                                float endRange)
        Generates a Gaussian random number greater or equal to the stRange and less than or equal to the endRange.
        Parameters:
        stRange - the random number will be greater than or equal to this number
        endRange - the random number will be less than or equal to this number
        Returns:
        float number in the range
      • genGaussianRandomNum

        public final double genGaussianRandomNum​(double stRange,
                                                 double endRange)
        Generates a Gaussian random number greater or equal to the stRange and less than or equal to the endRange.
        Parameters:
        stRange - the random number will be greater than or equal to this number
        endRange - the random number will be less than or equal to this number
        Returns:
        float number in the range
      • genStandardGaussian

        public final double genStandardGaussian()
      • genUniformRandomNum

        public final int genUniformRandomNum​(int stRange,
                                             int endRange)
        Generates a uniform random number greater or equal to the stRange and less than or equal to the endRange.
        Parameters:
        stRange - the random number will be greater than or equal to this number
        endRange - the random number will be less than or equal to this number
        Returns:
        integer number in the range
      • genUniformRandomNum

        public final float genUniformRandomNum​(float stRange,
                                               float endRange)
        Generates a uniform random number greater or equal to the stRange and less than or equal to the endRange.
        Parameters:
        stRange - the random number will be greater than or equal to this number
        endRange - the random number will be less than or equal to this number
        Returns:
        float number in the range
      • genUniformRandomNum

        public final double genUniformRandomNum​(double stRange,
                                                double endRange)
        Generates a uniform random number greater or equal to the stRange and less than or equal to the endRange.
        Parameters:
        stRange - the random number will be greater than or equal to this number
        endRange - the random number will be less than or equal to this number
        Returns:
        float number in the range
      • poissDecay

        public final double[] poissDecay​(int nEvents,
                                         double mu,
                                         double gain,
                                         double offset)
        This code is derived from PoissDecay.cpp, PoissonDeviate, PoissonRecur, and RandomDeviate, code accompanying Data Reduction and Error Analysis for the Physical Sciences, Third Edition, by Philip R. Bevington and D. Keith Robinson p(x, u)is the probability of observing x events where u is the average number of events observed. x must be zero or a positive integer. p(x, u) = (u**x)* exp(-u)/x! The sum of x from 0 to infinity of p(x, u) = 1. mean value of x = u variance of x = u Return gain * p(x, u) + offset
        Parameters:
        nEvents -
        mu - mean of Poisson distribtuion
        gain -
        offset -
        Returns: