edu.northwestern.at.utils.math.randomnumbers

## Class RandomVariable

- java.lang.Object
- - edu.northwestern.at.utils.math.randomnumbers.RandomVariable

-     public class RandomVariable
      extends java.lang.Object

  Provides methods for generating random numbers from a variety of statistical distributions.

  The Mersenne Twister algorithm is used to generate the uniform random numbers used by all methods in this class. The Mersenne Twister method provides an efficient portable means of generating random numbers with a long period of 219937-1. This class uses an implementation of Mesenne Twister written by Luc Maisonobe.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RandomVariable()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static double` | `beta(double a, double b)` Generate a random number from a beta random variable.
    `static boolean` | `binomial(double p)` Generate a random boolean value from a binomial random variable.
    `static int` | `binomialInteger(double p)` Generate a random integer value from a binomial random variable.
    `static double` | `cauchy(double median, double stddev)` Generate a random number from a Cauchy random variable.
    `static double` | `chisquare(int df)` Generate a random number from a chisquare random variable.
    `static double` | `dirac(double[] values, double[] pValues)` Generate a random number from a discrete random variable.
    `static double` | `exponential(double lambda)` Generate a random number from an exponential random variable.
    `static double` | `gamma(double alpha, double beta)` Generate a random number from a gamma distributed random variable.
    `static int` | `geometric(double p)` Generate a random value from a geometric random variable.
    `static double` | `logNormal(double mean, double stddev)` Generate a random number from a lognormal random variable.
    `static int` | `negativebinomial(int s, double p)` Generate a random value from a negative binomial variable.
    `static double` | `normal(double mean, double stddev)` Generate a random number from a Gaussian (Normal) random variable.
    `static int` | `poisson(double lambda)` Generate a random number from a poisson random variable.
    `static double` | `rand()` Generate a uniformly distributed random number between 0 and 1.
    `static int` | `randInt(int min, int max)` Generate a random integer within a specific range.
    `static double` | `triangular(double min, double max)` Generate a random number from a symmetric triangular random variable.
    `static double` | `triangular(double min, double median, double max)` Generate a random number from a non-symmetric triangular random variable.
    `static double` | `uniform(double min, double max)` Generate a random number from a uniform random variable.
    `static double` | `weibull(double eta, double beta)` Generate a random number from a Weibull random variable.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RandomVariable

          public RandomVariable()

  - ### Method Detail

    - #### rand

          public static double rand()

      Generate a uniformly distributed random number between 0 and 1.
      Returns:
        A double between 0 and 1.

        To use a different base random number generator, all you need to do is override this method in a subclass.

    - #### randInt

          public static int randInt(int min,
                    int max)

      Generate a random integer within a specific range.
      Parameters:
        `min` - Minimum value for the random integer.
        `max` - Maximum value for the random integer.
      Returns:
        An integer between min and max.

    - #### beta

          public static double beta(double a,
                    double b)

      Generate a random number from a beta random variable.
      Parameters:
        `a` - First parameter of the Beta random variable.
        `b` - Second parameter of the Beta random variable.
      Returns:
        Beta distributed random number.

    - #### binomial

          public static boolean binomial(double p)

      Generate a random boolean value from a binomial random variable.
      Parameters:
        `p` - Probability for binomial.
      Returns:
        true or false.

    - #### binomialInteger

          public static int binomialInteger(double p)

      Generate a random integer value from a binomial random variable.
      Parameters:
        `p` - Probability for binomial.
      Returns:
        0 or 1.

    - #### cauchy

          public static double cauchy(double median,
                      double stddev)

      Generate a random number from a Cauchy random variable.
      Parameters:
        `median` - Median of the Weibull random variable
        `stddev` - Second parameter of the Cauchy random variable.
      Returns:
        Cauchy distributed random number.

    - #### chisquare

          public static double chisquare(int df)

      Generate a random number from a chisquare random variable.
      Parameters:
        `df` - Degrees of freedom of the chisquare random variable.
      Returns:
        Random number.

        We compute the random chisquare value as the sum of "df" random normal deviates squared.

    - #### dirac

          public static double dirac(double[] values,
                     double[] pValues)

      Generate a random number from a discrete random variable.
      Parameters:
        `values` - Discrete values.
        `pValues` - Probability of each value.
      Returns:
        Random number.

    - #### exponential

          public static double exponential(double lambda)

      Generate a random number from an exponential random variable.
      Parameters:
        `lambda` - Parameter of the exponential random variable.
      Returns:
        Exponentially distributed random number.

        The mean of the exponential distribution is 1/lambda and the variance is 1/lambda^2 .

    - #### gamma

          public static double gamma(double alpha,
                     double beta)

      Generate a random number from a gamma distributed random variable.
      Parameters:
        `alpha` - First parameter of gamma distribution.
        `beta` - Second parameter of gamma distribution.
      Returns:
        Gamma distributed random number.

    - #### geometric

          public static int geometric(double p)

      Generate a random value from a geometric random variable.
      Parameters:
        `p` - Probability for geometric random variable.
      Returns:
        Geometrically distributed random value.

    - #### logNormal

          public static double logNormal(double mean,
                         double stddev)

      Generate a random number from a lognormal random variable.
      Parameters:
        `mean` - Mean of the normal random variable.
        `stddev` - Standard deviation of the normal random variable.
      Returns:
        A lognormally distributed random number.

    - #### negativebinomial

          public static int negativebinomial(int s,
                             double p)

      Generate a random value from a negative binomial variable.
      Parameters:
        `s` -
        `p` - Probability for negative binomial random variable.
      Returns:
        Random value from negative binomial distribution.

    - #### normal

          public static double normal(double mean,
                      double stddev)

      Generate a random number from a Gaussian (Normal) random variable.
      Parameters:
        `mean` - Mean of the random variable.
        `stddev` - Standard deviation of the random variable.
      Returns:
        Random number from normal distribution.

    - #### poisson

          public static int poisson(double lambda)

      Generate a random number from a poisson random variable.
      Parameters:
        `lambda` - Parameter of the exponential random variable.
      Returns:
        Random number from Poisson distribution.

    - #### triangular

          public static double triangular(double min,
                          double max)

      Generate a random number from a symmetric triangular random variable.
      Parameters:
        `min` - Minimum value of the random variable.
        `max` - Maximum value of the random variable.
      Returns:
        Symmetric triangular distributed random variable.

    - #### triangular

          public static double triangular(double min,
                          double median,
                          double max)

      Generate a random number from a non-symmetric triangular random variable.
      Parameters:
        `min` - Minimum value of the random variable.
        `median` - Value of the random variable which has maximum density.
        `max` - Maximum value of the random variable.
      Returns:
        Nonsymmetric triangular random variable.

    - #### uniform

          public static double uniform(double min,
                       double max)

      Generate a random number from a uniform random variable.
      Parameters:
        `min` - Mininum value for the random variable.
        `max` - Maximum value for the random variable.
      Returns:
        A random double between min and max.

    - #### weibull

          public static double weibull(double eta,
                       double beta)

      Generate a random number from a Weibull random variable.
      Parameters:
        `eta` - First parameter of the Weibull random variable.
        `beta` - Second parameter of the Weibull random variable.
      Returns:
        Weibull distributed random number.