Class Randoms


  • public final class Randoms
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Randoms()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean chance​(int target)
      Checks if the given {@param target} is less than or equal to a random value between 0(inclusive) and 100 (exclusive)
      static boolean chance​(int target, int overall)
      Checks if the given {@param target} is less than or equal to a random value between 0(inclusive) and {@param overall}(exclusive) Method just returns Calculations.random(overall) <= target
      static java.util.Random getSecureRandom()  
      static double getSeededDouble​(java.lang.String seed, double min, double max)  
      static int getSeededInt​(java.lang.String seed, int min, int max)  
      static double nextGammaRandom​(int shape, int scale)
      Generates a random value from the GammaDistribution
      static double nextGaussianRandom​(double mean, double sigma)
      Generates a random value from the Normal (or Gaussian) distribution with specified mean and standard deviation.
      static double nextHypergeometricRandom​(int populationSize, int numberOfSuccesses, int sampleSize)
      Generates a random value from the HypergeometricDistribution.
      static double nextLogNormalDistributionRandom​(double scale, double shape)
      Generates a lognormal distribution using the provided parameters with an inverse absolute accuracy of 1e-9 and uses a Well19937c number generator to return a sample
      static double random​(double lower, double upper)
      Generates a uniformly distributed random value from the open interval (lower, upper) (i.e., endpoints excluded).
      static int random​(int high)
      Returns a number between 0 (inclusive) and high (exclusive)
      static int random​(int min, int max)
      Gets a random number between min (inclusive) and max (exclusive)
      static long random​(long min, long max)
      Gets a random number between min (inclusive) and max (exclusive)
      static void setSeed​(long seed)  
      static void setSeed​(java.lang.String salt)  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Randoms

        public Randoms()
    • Method Detail

      • random

        public static int random​(int high)
        Returns a number between 0 (inclusive) and high (exclusive)
        Parameters:
        high - upper bounds of random number (exclusive)
        Returns:
        int between 0(inclusive) and max(exclusive)
      • random

        public static int random​(int min,
                                 int max)
        Gets a random number between min (inclusive) and max (exclusive)
        Parameters:
        min - minimum number
        max - maximum number
        Returns:
        int between min(inclusive) and max(exclusive)
      • nextLogNormalDistributionRandom

        public static double nextLogNormalDistributionRandom​(double scale,
                                                             double shape)
                                                      throws org.apache.commons.math3.exception.NotStrictlyPositiveException
        Generates a lognormal distribution using the provided parameters with an inverse absolute accuracy of 1e-9 and uses a Well19937c number generator to return a sample
        Parameters:
        scale - scale parameter (median of the distribution)
        shape - shape parameter (std. dev. of the log of the distribution)
        Returns:
        a sample from the distribution
        Throws:
        org.apache.commons.math3.exception.NotStrictlyPositiveException - if shape is less than or equal to 0
      • random

        public static double random​(double lower,
                                    double upper)
        Generates a uniformly distributed random value from the open interval (lower, upper) (i.e., endpoints excluded).
        Parameters:
        lower - the exclusive lower bound of the support
        upper - the exclusive upper bound of the support
        Returns:
        a uniformly distributed random value between lower and upper (exclusive)
        Throws:
        org.apache.commons.math3.exception.NumberIsTooLargeException - if lower is greater than upper.
        org.apache.commons.math3.exception.NotFiniteNumberException - if one of the bounds is infinite
        org.apache.commons.math3.exception.NotANumberException - if one of the bounds is NaN
      • random

        public static long random​(long min,
                                  long max)
        Gets a random number between min (inclusive) and max (exclusive)
        Parameters:
        min - minimum number
        max - maximum number
        Returns:
        Long between min(inclusive) and max(exclusive)
      • nextGaussianRandom

        public static double nextGaussianRandom​(double mean,
                                                double sigma)
        Generates a random value from the Normal (or Gaussian) distribution with specified mean and standard deviation.
        Parameters:
        mean - the standard mean of the distribution
        sigma - the standard deviation of the distribution
        Returns:
        a random value following the specified Gaussian distribution.
        Throws:
        org.apache.commons.math3.exception.NotStrictlyPositiveException - if sigma less or equal to 0.
      • nextHypergeometricRandom

        public static double nextHypergeometricRandom​(int populationSize,
                                                      int numberOfSuccesses,
                                                      int sampleSize)
        Generates a random value from the HypergeometricDistribution.
        Parameters:
        populationSize - the population size of the Hypergeometric distribution.
        numberOfSuccesses - number of successes in the population of the Hypergeometric distribution.
        sampleSize - the sample size of the Hypergeometric distribution.
        Returns:
        random value sampled from the Hypergeometric(populationSize, numberOfSuccesses, sampleSize) distribution.
        Throws:
        org.apache.commons.math3.exception.NotStrictlyPositiveException - if shape less or equal to 0 or scale less or equal to 0.
      • nextGammaRandom

        public static double nextGammaRandom​(int shape,
                                             int scale)
        Generates a random value from the GammaDistribution
        Parameters:
        shape - the median of the Gamma distribution
        scale - the scale parameter of the Gamma distribution
        Returns:
        random value sampled from the Gamma(shape, scale) distribution.
        Throws:
        org.apache.commons.math3.exception.NotStrictlyPositiveException - if shape less or equal to 0 or scale less or equal to 0.
      • setSeed

        public static void setSeed​(long seed)
      • setSeed

        public static void setSeed​(java.lang.String salt)
      • getSecureRandom

        public static java.util.Random getSecureRandom()
      • chance

        public static boolean chance​(int target,
                                     int overall)
        Checks if the given {@param target} is less than or equal to a random value between 0(inclusive) and {@param overall}(exclusive) Method just returns Calculations.random(overall) <= target
        Parameters:
        target - target value to check
        overall - overall value for a 0 to overall random check
        Returns:
        true if {@param target} is less than or equal to random(int) with {@param overall} passed to random
      • chance

        public static boolean chance​(int target)
        Checks if the given {@param target} is less than or equal to a random value between 0(inclusive) and 100 (exclusive)
        Parameters:
        target - target value to check for
        Returns:
        true if {@param target} is less than or equal to a random value between 0(inclusive) and 100 (exclusive)
      • getSeededInt

        public static int getSeededInt​(java.lang.String seed,
                                       int min,
                                       int max)
      • getSeededDouble

        public static double getSeededDouble​(java.lang.String seed,
                                             double min,
                                             double max)