Class RandomVariates


  • public final class RandomVariates
    extends Object
    This utility class provides methods for generating random variates from different distributions.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int nextBinomial​(int n, double p)
      Generates a pseudorandom integer from a binomial distribution.
      static int nextBinomial​(int n, double p, Random r)
      Generates a pseudorandom integer from a binomial distribution.
      static int nextBinomial​(int n, double p, SplittableRandom r)
      Generates a pseudorandom integer from a binomial distribution.
      static double nextCauchy​(double scale)
      Generates a pseudorandom number from a Cauchy distribution with median 0 and chosen scale parameter.
      static double nextCauchy​(double median, double scale)
      Generates a pseudorandom number from a Cauchy distribution.
      static double nextCauchy​(double median, double scale, Random r)
      Generates a pseudorandom number from a Cauchy distribution.
      static double nextCauchy​(double median, double scale, SplittableRandom r)
      Generates a pseudorandom number from a Cauchy distribution.
      static double nextCauchy​(double scale, Random r)
      Generates a pseudorandom number from a Cauchy distribution with median 0 and chosen scale parameter.
      static double nextCauchy​(double scale, SplittableRandom r)
      Generates a pseudorandom number from a Cauchy distribution with median 0 and chosen scale parameter.
      static double nextGaussian()
      Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1.
      static double nextGaussian​(double sigma)
      Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, of your choosing.
      static double nextGaussian​(double sigma, Random r)
      Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, of your choosing.
      static double nextGaussian​(double sigma, SplittableRandom r)
      Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, of your choosing.
      static double nextGaussian​(Random r)
      Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1.
      static double nextGaussian​(SplittableRandom r)
      Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1.
    • Method Detail

      • nextBinomial

        public static int nextBinomial​(int n,
                                       double p)
        Generates a pseudorandom integer from a binomial distribution. The source of randomness is via the ThreadLocalRandom class, and thus this method is both safe and efficient for use with threads.
        Parameters:
        n - Number of trials for the binomial distribution.
        p - The probability of a successful trial.
        Returns:
        A pseudorandom integer from a binomial distribution.
      • nextBinomial

        public static int nextBinomial​(int n,
                                       double p,
                                       Random r)
        Generates a pseudorandom integer from a binomial distribution.
        Parameters:
        n - Number of trials for the binomial distribution.
        p - The probability of a successful trial.
        r - The source of randomness.
        Returns:
        A pseudorandom integer from a binomial distribution.
      • nextBinomial

        public static int nextBinomial​(int n,
                                       double p,
                                       SplittableRandom r)
        Generates a pseudorandom integer from a binomial distribution.
        Parameters:
        n - Number of trials for the binomial distribution.
        p - The probability of a successful trial.
        r - The source of randomness.
        Returns:
        A pseudorandom integer from a binomial distribution.
      • nextCauchy

        public static double nextCauchy​(double median,
                                        double scale)
        Generates a pseudorandom number from a Cauchy distribution.
        Parameters:
        median - The median of the Cauchy.
        scale - The scale parameter of the Cauchy.
        Returns:
        a pseudorandom number from a Cauchy distribution
      • nextCauchy

        public static double nextCauchy​(double scale)
        Generates a pseudorandom number from a Cauchy distribution with median 0 and chosen scale parameter.
        Parameters:
        scale - The scale parameter of the Cauchy.
        Returns:
        a pseudorandom number from a Cauchy distribution
      • nextCauchy

        public static double nextCauchy​(double median,
                                        double scale,
                                        Random r)
        Generates a pseudorandom number from a Cauchy distribution.
        Parameters:
        median - The median of the Cauchy.
        scale - The scale parameter of the Cauchy.
        r - The source of randomness.
        Returns:
        a pseudorandom number from a Cauchy distribution
      • nextCauchy

        public static double nextCauchy​(double scale,
                                        Random r)
        Generates a pseudorandom number from a Cauchy distribution with median 0 and chosen scale parameter.
        Parameters:
        scale - The scale parameter of the Cauchy.
        r - The source of randomness.
        Returns:
        a pseudorandom number from a Cauchy distribution
      • nextCauchy

        public static double nextCauchy​(double median,
                                        double scale,
                                        SplittableRandom r)
        Generates a pseudorandom number from a Cauchy distribution.
        Parameters:
        median - The median of the Cauchy.
        scale - The scale parameter of the Cauchy.
        r - The source of randomness.
        Returns:
        a pseudorandom number from a Cauchy distribution
      • nextCauchy

        public static double nextCauchy​(double scale,
                                        SplittableRandom r)
        Generates a pseudorandom number from a Cauchy distribution with median 0 and chosen scale parameter.
        Parameters:
        scale - The scale parameter of the Cauchy.
        r - The source of randomness.
        Returns:
        a pseudorandom number from a Cauchy distribution
      • nextGaussian

        public static double nextGaussian​(double sigma)
        Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, of your choosing. This method uses the library's current most-efficient algorithm for Gaussian random number generation, which may change in future releases. If you require a guarantee of the algorithm used, then see the API for the classes that implement specific Gaussian algorithms. ThreadLocalRandom is used as the pseudorandom number generator for the source of randomness.
        Parameters:
        sigma - The standard deviation of the Gaussian.
        Returns:
        A random number from a Gaussian distribution with mean 0 and standard deviation sigma.
      • nextGaussian

        public static double nextGaussian​(double sigma,
                                          Random r)
        Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, of your choosing. This method uses the library's current most-efficient algorithm for Gaussian random number generation, which may change in future releases. If you require a guarantee of the algorithm used, then see the API for the classes that implement specific Gaussian algorithms.
        Parameters:
        sigma - The standard deviation of the Gaussian.
        r - The pseudorandom number generator to use for the source of randomness.
        Returns:
        A random number from a Gaussian distribution with mean 0 and standard deviation sigma.
      • nextGaussian

        public static double nextGaussian​(double sigma,
                                          SplittableRandom r)
        Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, of your choosing. This method uses the library's current most-efficient algorithm for Gaussian random number generation, which may change in future releases. If you require a guarantee of the algorithm used, then see the API for the classes that implement specific Gaussian algorithms.
        Parameters:
        sigma - The standard deviation of the Gaussian.
        r - The pseudorandom number generator to use for the source of randomness.
        Returns:
        A random number from a Gaussian distribution with mean 0 and standard deviation sigma.
      • nextGaussian

        public static double nextGaussian()
        Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1. This method uses the library's current most-efficient algorithm for Gaussian random number generation, which may change in future releases. If you require a guarantee of the algorithm used, then see the API for the classes that implement specific Gaussian algorithms. ThreadLocalRandom is used as the pseudorandom number generator for the source of randomness.
        Returns:
        A random number from a Gaussian distribution with mean 0 and standard deviation 1.
      • nextGaussian

        public static double nextGaussian​(Random r)
        Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1. This method uses the library's current most-efficient algorithm for Gaussian random number generation, which may change in future releases. If you require a guarantee of the algorithm used, then see the API for the classes that implement specific Gaussian algorithms.
        Parameters:
        r - The pseudorandom number generator to use for the source of randomness.
        Returns:
        A random number from a Gaussian distribution with mean 0 and standard deviation 1.
      • nextGaussian

        public static double nextGaussian​(SplittableRandom r)
        Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1. This method uses the library's current most-efficient algorithm for Gaussian random number generation, which may change in future releases. If you require a guarantee of the algorithm used, then see the API for the classes that implement specific Gaussian algorithms.
        Parameters:
        r - The pseudorandom number generator to use for the source of randomness.
        Returns:
        A random number from a Gaussian distribution with mean 0 and standard deviation 1.