Class JSLRandom


  • public class JSLRandom
    extends java.lang.Object
    The purpose of this class is to facilitate random variate generation from various distributions through a set of static class methods.

    Each method marked rXXXX will generate random variates from the named distribution. The user has the option of supplying a RNStreamIfc as the source of the randomness. Methods that do not have a RNStreamIfc parameter use, getDefaultRNStream() as the source of randomness. That is, they all share the same stream, which is the default stream from the default random number stream factory. The user has the option of supplying a stream number to identify the stream from the underlying stream provider. By default, stream 1 is the default stream for the default provider. Stream 2 refers to the 2nd stream, etc.

    Also provides a number of methods for sampling with and without replacement from arrays and lists as well as creating permutations of arrays and lists.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  JSLRandom.AlgoType  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double[] copyFirstNValues​(double[] x, int n)
      Facilitates sampling without replacement to a new array.
      static java.util.stream.DoubleStream createDoubleStream()  
      static RNStreamIfc getDefaultRNStream()  
      static RNStreamProviderIfc getRNStreamProvider()  
      static int getStreamNumber​(RNStreamIfc stream)  
      static boolean isValidCDF​(double[] cdf)  
      static boolean isValidPMF​(double[] prob)
      Each element must be in (0,1) and sum of elements must be less than or equal to 1.0
      static double[] makeCDF​(double[] prob)  
      static RNStreamIfc nextRNStream()  
      static void permutation​(boolean[] x)
      Randomly permutes the supplied array using the default random number generator.
      static void permutation​(boolean[] x, int streamNum)
      Randomly permutes the supplied array using the supplied random number generator, the array is changed.
      static void permutation​(boolean[] x, RNStreamIfc rng)
      Randomly permutes the supplied array using the supplied random number generator, the array is changed.
      static void permutation​(double[] x)
      Randomly permutes the supplied array using the default random number generator.
      static void permutation​(double[] x, int streamNum)
      Randomly permutes the supplied array using the supplied random number generator, the array is changed
      static void permutation​(double[] x, RNStreamIfc rng)
      Randomly permutes the supplied array using the supplied random number generator, the array is changed
      static void permutation​(int[] x)
      Randomly permutes the supplied array using the default random number generator.
      static void permutation​(int[] x, int streamNum)
      Randomly permutes the supplied array using the supplied random number generator, the array is changed.
      static void permutation​(int[] x, RNStreamIfc rng)
      Randomly permutes the supplied array using the supplied random number generator, the array is changed.
      static <T> void permutation​(java.util.List<T> x)
      Randomly permutes the supplied List using the supplied random number generator, the list is changed
      static <T> void permutation​(java.util.List<T> x, int streamNum)
      Randomly permutes the supplied List using the supplied random number generator, the list is changed
      static <T> void permutation​(java.util.List<T> x, RNStreamIfc rng)
      Randomly permutes the supplied List using the supplied random number generator, the list is changed
      static <T> void permutation​(T[] x)
      Randomly permutes the supplied array using the default random number generator.
      static <T> void permutation​(T[] x, int streamNum)
      Randomly permutes the supplied array using the supplied random number generator, the array is changed
      static <T> void permutation​(T[] x, RNStreamIfc rng)
      Randomly permutes the supplied array using the supplied random number generator, the array is changed
      static double randomlySelect​(double[] array)
      Randomly select an element from the array
      static double randomlySelect​(double[] array, double[] cdf)
      Randomly selects from the array using the supplied cdf
      static double randomlySelect​(double[] array, double[] cdf, int streamNum)
      Randomly selects from the array using the supplied cdf
      static double randomlySelect​(double[] array, double[] cdf, RNStreamIfc rng)
      Randomly selects from the array using the supplied cdf
      static double randomlySelect​(double[] array, int streamNum)
      Randomly select an element from the array
      static double randomlySelect​(double[] array, RNStreamIfc rng)
      Randomly select an element from the array
      static int randomlySelect​(int[] array)
      Randomly select an element from the array
      static int randomlySelect​(int[] array, double[] cdf)
      Randomly selects from the array using the supplied cdf
      static int randomlySelect​(int[] array, double[] cdf, int streamNum)
      Randomly selects from the array using the supplied cdf
      static int randomlySelect​(int[] array, double[] cdf, RNStreamIfc rng)
      Randomly selects from the array using the supplied cdf
      static int randomlySelect​(int[] array, int streamNum)
      Randomly select an element from the array
      static int randomlySelect​(int[] array, RNStreamIfc rng)
      Randomly select an element from the array
      static <T> T randomlySelect​(java.util.List<T> list)
      Randomly select from the list using the default stream
      static <T> T randomlySelect​(java.util.List<T> list, double[] cdf)
      Randomly selects from the list using the supplied cdf
      static <T> T randomlySelect​(java.util.List<T> list, double[] cdf, int streamNum)
      Randomly selects from the list using the supplied cdf
      static <T> T randomlySelect​(java.util.List<T> list, double[] cdf, RNStreamIfc rng)
      Randomly selects from the list using the supplied cdf
      static <T> T randomlySelect​(java.util.List<T> list, int streamNum)
      Randomly select from the list
      static <T> T randomlySelect​(java.util.List<T> list, RNStreamIfc rng)
      Randomly select from the list
      static double rBernoulli​(double pSuccess)  
      static double rBernoulli​(double pSuccess, int streamNum)  
      static double rBernoulli​(double pSuccess, RNStreamIfc stream)  
      static double rBeta​(double alpha1, double alpha2)
      This beta is restricted to the range of (0,1)
      static double rBeta​(double alpha1, double alpha2, int streamNum)
      This beta is restricted to the range of (0,1)
      static double rBeta​(double alpha1, double alpha2, RNStreamIfc rng)
      This beta is restricted to the range of (0,1)
      static double rBetaG​(double alpha1, double alpha2, double minimum, double maximum)
      This beta is restricted to the range of (minimum,maximum)
      static double rBetaG​(double alpha1, double alpha2, double minimum, double maximum, int streamNum)
      This beta is restricted to the range of (minimum,maximum)
      static double rBetaG​(double alpha1, double alpha2, double minimum, double maximum, RNStreamIfc rng)
      This beta is restricted to the range of (minimum,maximum)
      static int rBinomial​(double pSuccess, int nTrials)  
      static int rBinomial​(double pSuccess, int nTrials, int streamNum)  
      static int rBinomial​(double pSuccess, int nTrials, RNStreamIfc stream)  
      static double rChiSquared​(double dof)  
      static double rChiSquared​(double dof, int streamNum)  
      static double rChiSquared​(double dof, RNStreamIfc rng)  
      static int rDUniform​(int minimum, int maximum)
      Generates a discrete uniform over the range
      static int rDUniform​(int minimum, int maximum, int streamNum)
      Generates a discrete uniform over the range
      static int rDUniform​(int minimum, int maximum, RNStreamIfc rng)
      Generates a discrete uniform over the range
      static double rExponential​(double mean)  
      static double rExponential​(double mean, int streamNum)  
      static double rExponential​(double mean, RNStreamIfc rng)  
      static double rGamma​(double shape, double scale)  
      static double rGamma​(double shape, double scale, int streamNum)  
      static double rGamma​(double shape, double scale, int streamNum, JSLRandom.AlgoType type)  
      static double rGamma​(double shape, double scale, RNStreamIfc rng)  
      static double rGamma​(double shape, double scale, RNStreamIfc rng, JSLRandom.AlgoType type)  
      static int rGeometric​(double pSuccess)  
      static int rGeometric​(double pSuccess, int streamNum)  
      static int rGeometric​(double pSuccess, RNStreamIfc rng)  
      static double rJohnsonB​(double alpha1, double alpha2, double min, double max)  
      static double rJohnsonB​(double alpha1, double alpha2, double min, double max, int streamNum)  
      static double rJohnsonB​(double alpha1, double alpha2, double min, double max, RNStreamIfc rng)  
      static double rLaplace​(double mean, double scale)
      Generates according to a Laplace(mean, scale)
      static double rLaplace​(double mean, double scale, int streamNum)
      Generates according to a Laplace(mean, scale)
      static double rLaplace​(double mean, double scale, RNStreamIfc rng)
      Generates according to a Laplace(mean, scale)
      static double rLogLogistic​(double shape, double scale)  
      static double rLogLogistic​(double shape, double scale, int streamNum)  
      static double rLogLogistic​(double shape, double scale, RNStreamIfc rng)  
      static double rLogNormal​(double mean, double variance)  
      static double rLogNormal​(double mean, double variance, int streamNum)  
      static double rLogNormal​(double mean, double variance, RNStreamIfc rng)  
      static int rNegBinomial​(double pSuccess, double rSuccesses)  
      static int rNegBinomial​(double pSuccess, double rSuccesses, int streamNum)  
      static int rNegBinomial​(double pSuccess, double rSuccesses, RNStreamIfc rng)  
      static double rNormal()
      Generates a N(0,1) random value using the default stream
      static double rNormal​(double mean, double variance)  
      static double rNormal​(double mean, double variance, int streamNum)  
      static double rNormal​(double mean, double variance, RNStreamIfc rng)  
      static double rNormal​(int streamNum)
      Generates a N(0,1) random value using the supplied stream number
      static double rNormal​(RNStreamIfc rng)
      Generates a N(0,1) random value using the supplied stream
      static RNStreamIfc rnStream​(int streamNum)  
      static double rPearsonType5​(double shape, double scale)  
      static double rPearsonType5​(double shape, double scale, int streamNum)  
      static double rPearsonType5​(double shape, double scale, RNStreamIfc rng)  
      static double rPearsonType6​(double alpha1, double alpha2, double beta)
      Pearson Type 6
      static double rPearsonType6​(double alpha1, double alpha2, double beta, int streamNum)
      Pearson Type 6
      static double rPearsonType6​(double alpha1, double alpha2, double beta, RNStreamIfc rng)
      Pearson Type 6
      static int rPoisson​(double mean)  
      static int rPoisson​(double mean, int streamNum)  
      static int rPoisson​(double mean, RNStreamIfc rng)  
      static double rTriangular​(double min, double mode, double max)  
      static double rTriangular​(double min, double mode, double max, int streamNum)  
      static double rTriangular​(double min, double mode, double max, RNStreamIfc rng)  
      static double rUniform()
      Generates a continuous U(0,1) using the default stream
      static double rUniform​(double minimum, double maximum)
      Generates a continuous uniform over the range
      static double rUniform​(double minimum, double maximum, int streamNum)
      Generates a continuous uniform over the range
      static double rUniform​(double minimum, double maximum, RNStreamIfc rng)
      Generates a continuous uniform over the range
      static double rUniform​(int streamNum)
      Generates a continuous U(0,1) using the supplied stream number
      static double rUniform​(RNStreamIfc rnStream)
      Generates a continuous U(0,1) using the supplied stream
      static double rWeibull​(double shape, double scale)  
      static double rWeibull​(double shape, double scale, int streamNum)  
      static double rWeibull​(double shape, double scale, RNStreamIfc rng)  
      static void sampleWithoutReplacement​(boolean[] x, int sampleSize)
      The array x is changed, such that the first sampleSize elements contain the generated sample.
      static void sampleWithoutReplacement​(boolean[] x, int sampleSize, int streamNum)
      The array x is changed, such that the first sampleSize elements contain the generated sample.
      static void sampleWithoutReplacement​(boolean[] x, int sampleSize, RNStreamIfc rng)
      The array x is changed, such that the first sampleSize elements contain the generated sample.
      static void sampleWithoutReplacement​(double[] x, int sampleSize)
      The array x is changed, such that the first sampleSize elements contain the sample.
      static void sampleWithoutReplacement​(double[] x, int sampleSize, int streamNum)
      The array x is changed, such that the first sampleSize elements contain the sample.
      static void sampleWithoutReplacement​(double[] x, int sampleSize, RNStreamIfc rng)
      The array x is changed, such that the first sampleSize elements contain the sample.
      static void sampleWithoutReplacement​(int[] x, int sampleSize)
      The array x is changed, such that the first sampleSize elements contain the generated sample.
      static void sampleWithoutReplacement​(int[] x, int sampleSize, int streamNum)
      The array x is changed, such that the first sampleSize elements contain the generated sample.
      static void sampleWithoutReplacement​(int[] x, int sampleSize, RNStreamIfc rng)
      The array x is changed, such that the first sampleSize elements contain the generated sample.
      static <T> void sampleWithoutReplacement​(java.util.List<T> x, int sampleSize)
      The List x is changed, such that the first sampleSize elements contain the generate.
      static <T> void sampleWithoutReplacement​(java.util.List<T> x, int sampleSize, int streamNum)
      The List x is changed, such that the first sampleSize elements contain the generate.
      static <T> void sampleWithoutReplacement​(java.util.List<T> x, int sampleSize, RNStreamIfc rng)
      The List x is changed, such that the first sampleSize elements contain the generate.
      static <T> void sampleWithoutReplacement​(T[] x, int sampleSize)
      The array x is changed, such that the first sampleSize elements contain the generated sample.
      static <T> void sampleWithoutReplacement​(T[] x, int sampleSize, int streamNum)
      The array x is changed, such that the first sampleSize elements contain the generated sample.
      static <T> void sampleWithoutReplacement​(T[] x, int sampleSize, RNStreamIfc rng)
      The array x is changed, such that the first sampleSize elements contain the generated sample.
      static void setRNStreamProvider​(RNStreamProviderIfc streamProvider)
      Sets the underlying stream provider for all JSLRandom method usage
      • Methods inherited from class java.lang.Object

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

      • setRNStreamProvider

        public static void setRNStreamProvider​(RNStreamProviderIfc streamProvider)
        Sets the underlying stream provider for all JSLRandom method usage
        Parameters:
        streamProvider - an instance of a stream provider
      • getRNStreamProvider

        public static RNStreamProviderIfc getRNStreamProvider()
        Returns:
        the provider that is currently being used for all JSLRandom method calls
      • nextRNStream

        public static RNStreamIfc nextRNStream()
        Returns:
        gets the next stream of pseudo random numbers from the default random number stream provider
      • getStreamNumber

        public static int getStreamNumber​(RNStreamIfc stream)
        Parameters:
        stream - the stream associated with the default stream provider
        Returns:
        the number associated with the provided stream or -1 if the stream was not provided by the default provider
      • rnStream

        public static RNStreamIfc rnStream​(int streamNum)
        Parameters:
        streamNum - the stream number associated with the stream
        Returns:
        the stream associated with the stream number from the underlying stream provider
      • getDefaultRNStream

        public static RNStreamIfc getDefaultRNStream()
        Returns:
        the default stream from the default random number stream provider
      • createDoubleStream

        public static java.util.stream.DoubleStream createDoubleStream()
        Returns:
        returns a new stream from the default stream factory using the Stream API
      • rBernoulli

        public static double rBernoulli​(double pSuccess)
        Parameters:
        pSuccess - the probability of success, must be in (0,1)
        Returns:
        the random value
      • rBernoulli

        public static double rBernoulli​(double pSuccess,
                                        int streamNum)
        Parameters:
        pSuccess - the probability of success, must be in (0,1)
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rBernoulli

        public static double rBernoulli​(double pSuccess,
                                        RNStreamIfc stream)
        Parameters:
        pSuccess - the probability of success, must be in (0,1)
        stream - the RNStreamIfc
        Returns:
        the random value
      • rBinomial

        public static int rBinomial​(double pSuccess,
                                    int nTrials)
        Parameters:
        pSuccess - the probability of success, must be in (0,1)
        nTrials - the number of trials, must be greater than 0
        Returns:
        the random value
      • rBinomial

        public static int rBinomial​(double pSuccess,
                                    int nTrials,
                                    int streamNum)
        Parameters:
        pSuccess - the probability of success, must be in (0,1)
        nTrials - the number of trials, must be greater than 0
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rBinomial

        public static int rBinomial​(double pSuccess,
                                    int nTrials,
                                    RNStreamIfc stream)
        Parameters:
        pSuccess - the probability of success, must be in (0,1)
        nTrials - the number of trials, must be greater than 0
        stream - the RNStreamIfc, must not be null
        Returns:
        the random value
      • rPoisson

        public static int rPoisson​(double mean)
        Parameters:
        mean - the mean of the Poisson, must be greater than 0
        Returns:
        the random value
      • rPoisson

        public static int rPoisson​(double mean,
                                   int streamNum)
        Parameters:
        mean - the mean of the Poisson, must be greater than 0
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rPoisson

        public static int rPoisson​(double mean,
                                   RNStreamIfc rng)
        Parameters:
        mean - the mean of the Poisson, must be greater than 0
        rng - the RNStreamIfc, must not be null
        Returns:
        the random value
      • rDUniform

        public static int rDUniform​(int minimum,
                                    int maximum)
        Generates a discrete uniform over the range
        Parameters:
        minimum - the minimum of the range
        maximum - the maximum of the range
        Returns:
        the random value
      • rDUniform

        public static int rDUniform​(int minimum,
                                    int maximum,
                                    int streamNum)
        Generates a discrete uniform over the range
        Parameters:
        minimum - the minimum of the range
        maximum - the maximum of the range
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rDUniform

        public static int rDUniform​(int minimum,
                                    int maximum,
                                    RNStreamIfc rng)
        Generates a discrete uniform over the range
        Parameters:
        minimum - the minimum of the range
        maximum - the maximum of the range
        rng - the RNStreamIfc, must not be null
        Returns:
        the random value
      • rGeometric

        public static int rGeometric​(double pSuccess)
        Parameters:
        pSuccess - the probability of success, must be in (0,1)
        Returns:
        the random value
      • rGeometric

        public static int rGeometric​(double pSuccess,
                                     int streamNum)
        Parameters:
        pSuccess - the probability of success, must be in (0,1)
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rGeometric

        public static int rGeometric​(double pSuccess,
                                     RNStreamIfc rng)
        Parameters:
        pSuccess - the probability of success, must be in (0,1)
        rng - the RNStreamIfc, must not be null
        Returns:
        the random value
      • rNegBinomial

        public static int rNegBinomial​(double pSuccess,
                                       double rSuccesses)
        Parameters:
        pSuccess - the probability of success, must be in (0,1)
        rSuccesses - number of trials until rth success, must be greater than 0
        Returns:
        the random value
      • rNegBinomial

        public static int rNegBinomial​(double pSuccess,
                                       double rSuccesses,
                                       int streamNum)
        Parameters:
        pSuccess - the probability of success, must be in (0,1)
        rSuccesses - number of trials until rth success
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rNegBinomial

        public static int rNegBinomial​(double pSuccess,
                                       double rSuccesses,
                                       RNStreamIfc rng)
        Parameters:
        pSuccess - the probability of success, must be in (0,1)
        rSuccesses - number of trials until rth success
        rng - the RNStreamIfc, must not be null
        Returns:
        the random value
      • rUniform

        public static double rUniform()
        Generates a continuous U(0,1) using the default stream
        Returns:
        the random value
      • rUniform

        public static double rUniform​(int streamNum)
        Generates a continuous U(0,1) using the supplied stream number
        Parameters:
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rUniform

        public static double rUniform​(RNStreamIfc rnStream)
        Generates a continuous U(0,1) using the supplied stream
        Parameters:
        rnStream - the RNStreamIfc, must not be null
        Returns:
        the random value
      • rUniform

        public static double rUniform​(double minimum,
                                      double maximum)
        Generates a continuous uniform over the range
        Parameters:
        minimum - the minimum of the range, must be less than maximum
        maximum - the maximum of the range
        Returns:
        the random value
      • rUniform

        public static double rUniform​(double minimum,
                                      double maximum,
                                      int streamNum)
        Generates a continuous uniform over the range
        Parameters:
        minimum - the minimum of the range, must be less than maximum
        maximum - the maximum of the range
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rUniform

        public static double rUniform​(double minimum,
                                      double maximum,
                                      RNStreamIfc rng)
        Generates a continuous uniform over the range
        Parameters:
        minimum - the minimum of the range, must be less than maximum
        maximum - the maximum of the range
        rng - the RNStreamIfc, must not be null
        Returns:
        the random value
      • rNormal

        public static double rNormal()
        Generates a N(0,1) random value using the default stream
        Returns:
        the random value
      • rNormal

        public static double rNormal​(int streamNum)
        Generates a N(0,1) random value using the supplied stream number
        Parameters:
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rNormal

        public static double rNormal​(RNStreamIfc rng)
        Generates a N(0,1) random value using the supplied stream
        Parameters:
        rng - the RNStreamIfc, must not null
        Returns:
        the random value
      • rNormal

        public static double rNormal​(double mean,
                                     double variance)
        Parameters:
        mean - the mean of the normal
        variance - the variance of the normal, must be greater than 0
        Returns:
        the random value
      • rNormal

        public static double rNormal​(double mean,
                                     double variance,
                                     int streamNum)
        Parameters:
        mean - the mean of the normal
        variance - the variance of the normal, must be greater than 0
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rNormal

        public static double rNormal​(double mean,
                                     double variance,
                                     RNStreamIfc rng)
        Parameters:
        mean - the mean of the normal
        variance - the variance of the normal, must be greater than 0
        rng - the RNStreamIfc, must not null
        Returns:
        the random value
      • rLogNormal

        public static double rLogNormal​(double mean,
                                        double variance)
        Parameters:
        mean - the mean of the lognormal, must be greater than 0
        variance - the variance of the lognormal, must be greater than 0
        Returns:
        the random value
      • rLogNormal

        public static double rLogNormal​(double mean,
                                        double variance,
                                        int streamNum)
        Parameters:
        mean - the mean of the lognormal, must be greater than 0
        variance - the variance of the lognormal, must be greater than 0
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rLogNormal

        public static double rLogNormal​(double mean,
                                        double variance,
                                        RNStreamIfc rng)
        Parameters:
        mean - the mean of the lognormal, must be greater than 0
        variance - the variance of the lognormal, must be greater than 0
        rng - the RNStreamIfc, must not be null
        Returns:
        the random value
      • rWeibull

        public static double rWeibull​(double shape,
                                      double scale)
        Parameters:
        shape - the shape, must be greater than 0
        scale - the scale, must be greater than 0
        Returns:
        the random value
      • rWeibull

        public static double rWeibull​(double shape,
                                      double scale,
                                      int streamNum)
        Parameters:
        shape - the shape, must be greater than 0
        scale - the scale, must be greater than 0
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rWeibull

        public static double rWeibull​(double shape,
                                      double scale,
                                      RNStreamIfc rng)
        Parameters:
        shape - the shape, must be greater than 0
        scale - the scale, must be greater than 0
        rng - the RNStreamIfc, must not null
        Returns:
        the random value
      • rExponential

        public static double rExponential​(double mean)
        Parameters:
        mean - the mean, must be greater than 0
        Returns:
        the random value
      • rExponential

        public static double rExponential​(double mean,
                                          int streamNum)
        Parameters:
        mean - the mean, must be greater than 0
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rExponential

        public static double rExponential​(double mean,
                                          RNStreamIfc rng)
        Parameters:
        mean - the mean, must be greater than 0
        rng - the RNStreamIfc, must not null
        Returns:
        the random value
      • rJohnsonB

        public static double rJohnsonB​(double alpha1,
                                       double alpha2,
                                       double min,
                                       double max)
        Parameters:
        alpha1 - alpha1 parameter
        alpha2 - alpha2 parameter
        min - the min
        max - the max
        Returns:
        the generated value
      • rJohnsonB

        public static double rJohnsonB​(double alpha1,
                                       double alpha2,
                                       double min,
                                       double max,
                                       int streamNum)
        Parameters:
        alpha1 - alpha1 parameter
        alpha2 - alpha2 parameter, must be greater than zero
        min - the min, must be less than max
        max - the max
        streamNum - the stream number from the stream provider to use
        Returns:
        the generated value
      • rJohnsonB

        public static double rJohnsonB​(double alpha1,
                                       double alpha2,
                                       double min,
                                       double max,
                                       RNStreamIfc rng)
        Parameters:
        alpha1 - alpha1 parameter
        alpha2 - alpha2 parameter, must be greater than zero
        min - the min, must be less than max
        max - the max
        rng - the RNStreamIfc, must not be null
        Returns:
        the generated value
      • rLogLogistic

        public static double rLogLogistic​(double shape,
                                          double scale)
        Parameters:
        shape - the shape
        scale - the scale
        Returns:
        the generated value
      • rLogLogistic

        public static double rLogLogistic​(double shape,
                                          double scale,
                                          int streamNum)
        Parameters:
        shape - the shape, must be greater than 0
        scale - the scale, must be greater than 0
        streamNum - the stream number from the stream provider to use
        Returns:
        the generated value
      • rLogLogistic

        public static double rLogLogistic​(double shape,
                                          double scale,
                                          RNStreamIfc rng)
        Parameters:
        shape - the shape, must be greater than 0
        scale - the scale, must be greater than 0
        rng - the RNStreamIfc, must not be null
        Returns:
        the generated value
      • rTriangular

        public static double rTriangular​(double min,
                                         double mode,
                                         double max)
        Parameters:
        min - the min, must be less than or equal to mode
        mode - the mode, must be less than or equal to max
        max - the max
        Returns:
        the random value
      • rTriangular

        public static double rTriangular​(double min,
                                         double mode,
                                         double max,
                                         int streamNum)
        Parameters:
        min - the min, must be less than or equal to mode
        mode - the mode, must be less than or equal to max
        max - the max
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rTriangular

        public static double rTriangular​(double min,
                                         double mode,
                                         double max,
                                         RNStreamIfc rng)
        Parameters:
        min - the min, must be less than or equal to mode
        mode - the mode, must be less than or equal to max
        max - the max
        rng - the RNStreamIfc, must not be null
        Returns:
        the random value
      • rGamma

        public static double rGamma​(double shape,
                                    double scale)
        Parameters:
        shape - the shape, must be greater than 0
        scale - the scale, must be greater than 0
        Returns:
        the generated value
      • rGamma

        public static double rGamma​(double shape,
                                    double scale,
                                    RNStreamIfc rng)
        Parameters:
        shape - the shape, must be greater than 0.0
        scale - the scale, must be greater than 0.0
        rng - the RNStreamIfc, must not null
        Returns:
        the generated value
      • rGamma

        public static double rGamma​(double shape,
                                    double scale,
                                    int streamNum)
        Parameters:
        shape - the shape, must be greater than 0.0
        scale - the scale, must be greater than 0.0
        streamNum - the stream number from the stream provider to use
        Returns:
        the generated value
      • rGamma

        public static double rGamma​(double shape,
                                    double scale,
                                    int streamNum,
                                    JSLRandom.AlgoType type)
        Parameters:
        shape - the shape, must be greater than 0.0
        scale - the scale, must be greater than 0.0
        streamNum - the stream number from the stream provider to use
        type - , must be appropriate algorithm type, if null then inverse transform is the default
        Returns:
        the generated value
      • rGamma

        public static double rGamma​(double shape,
                                    double scale,
                                    RNStreamIfc rng,
                                    JSLRandom.AlgoType type)
        Parameters:
        shape - the shape, must be greater than 0.0
        scale - the scale, must be greater than 0.0
        rng - the RNStreamIfc, must not null
        type - , must be appropriate algorithm type, if null then inverse transform is the default
        Returns:
        the generated value
      • rChiSquared

        public static double rChiSquared​(double dof)
        Parameters:
        dof - degrees of freedom, must be greater than 0
        Returns:
        the random value
      • rChiSquared

        public static double rChiSquared​(double dof,
                                         int streamNum)
        Parameters:
        dof - degrees of freedom, must be greater than 0
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rChiSquared

        public static double rChiSquared​(double dof,
                                         RNStreamIfc rng)
        Parameters:
        dof - degrees of freedom, must be greater than 0
        rng - the RNStreamIfc, must not be null
        Returns:
        the random value
      • rPearsonType5

        public static double rPearsonType5​(double shape,
                                           double scale)
        Parameters:
        shape - the shape, must be greater than 0
        scale - the scale, must be greater than 0
        Returns:
        the generated value
      • rPearsonType5

        public static double rPearsonType5​(double shape,
                                           double scale,
                                           int streamNum)
        Parameters:
        shape - the shape, must be greater than 0
        scale - the scale, must be greater than 0
        streamNum - the stream number from the stream provider to use
        Returns:
        the generated value
      • rPearsonType5

        public static double rPearsonType5​(double shape,
                                           double scale,
                                           RNStreamIfc rng)
        Parameters:
        shape - the shape, must be greater than 0
        scale - the scale, must be greater than 0
        rng - the RNStreamIfc, must not be null
        Returns:
        the generated value
      • rBeta

        public static double rBeta​(double alpha1,
                                   double alpha2)
        This beta is restricted to the range of (0,1)
        Parameters:
        alpha1 - alpha1 parameter
        alpha2 - alpha2 parameter
        Returns:
        the random value
      • rBeta

        public static double rBeta​(double alpha1,
                                   double alpha2,
                                   int streamNum)
        This beta is restricted to the range of (0,1)
        Parameters:
        alpha1 - alpha1 parameter
        alpha2 - alpha2 parameter
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rBeta

        public static double rBeta​(double alpha1,
                                   double alpha2,
                                   RNStreamIfc rng)
        This beta is restricted to the range of (0,1)
        Parameters:
        alpha1 - alpha1 parameter
        alpha2 - alpha2 parameter
        rng - the RNStreamIfc
        Returns:
        the random value
      • rBetaG

        public static double rBetaG​(double alpha1,
                                    double alpha2,
                                    double minimum,
                                    double maximum)
        This beta is restricted to the range of (minimum,maximum)
        Parameters:
        alpha1 - alpha1 parameter
        alpha2 - alpha2 parameter
        minimum - the minimum of the range
        maximum - the maximum of the range
        Returns:
        the random value
      • rBetaG

        public static double rBetaG​(double alpha1,
                                    double alpha2,
                                    double minimum,
                                    double maximum,
                                    int streamNum)
        This beta is restricted to the range of (minimum,maximum)
        Parameters:
        alpha1 - alpha1 parameter
        alpha2 - alpha2 parameter
        minimum - the minimum of the range, must be less than maximum
        maximum - the maximum of the range
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rBetaG

        public static double rBetaG​(double alpha1,
                                    double alpha2,
                                    double minimum,
                                    double maximum,
                                    RNStreamIfc rng)
        This beta is restricted to the range of (minimum,maximum)
        Parameters:
        alpha1 - alpha1 parameter
        alpha2 - alpha2 parameter
        minimum - the minimum of the range, must be less than maximum
        maximum - the maximum of the range
        rng - the RNStreamIfc
        Returns:
        the random value
      • rPearsonType6

        public static double rPearsonType6​(double alpha1,
                                           double alpha2,
                                           double beta)
        Pearson Type 6
        Parameters:
        alpha1 - alpha1 parameter
        alpha2 - alpha2 parameter
        beta - the beta parameter
        Returns:
        the random value
      • rPearsonType6

        public static double rPearsonType6​(double alpha1,
                                           double alpha2,
                                           double beta,
                                           int streamNum)
        Pearson Type 6
        Parameters:
        alpha1 - alpha1 parameter
        alpha2 - alpha2 parameter
        beta - the beta parameter, must be greater than 0
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rPearsonType6

        public static double rPearsonType6​(double alpha1,
                                           double alpha2,
                                           double beta,
                                           RNStreamIfc rng)
        Pearson Type 6
        Parameters:
        alpha1 - alpha1 parameter
        alpha2 - alpha2 parameter
        beta - the beta parameter, must be greater than 0
        rng - the RNStreamIfc, must not be null
        Returns:
        the random value
      • rLaplace

        public static double rLaplace​(double mean,
                                      double scale)
        Generates according to a Laplace(mean, scale)
        Parameters:
        mean - mean or location parameter
        scale - scale parameter, must be greater than 0
        Returns:
        the random value
      • rLaplace

        public static double rLaplace​(double mean,
                                      double scale,
                                      int streamNum)
        Generates according to a Laplace(mean, scale)
        Parameters:
        mean - mean or location parameter
        scale - scale parameter, must be greater than 0
        streamNum - the stream number from the stream provider to use
        Returns:
        the random value
      • rLaplace

        public static double rLaplace​(double mean,
                                      double scale,
                                      RNStreamIfc rng)
        Generates according to a Laplace(mean, scale)
        Parameters:
        mean - mean or location parameter
        scale - scale parameter, must be greater than 0
        rng - the RNStreamIfc, must not be null
        Returns:
        the random value
      • randomlySelect

        public static int randomlySelect​(int[] array)
        Randomly select an element from the array
        Parameters:
        array - the array to select from
        Returns:
        the randomly selected value
      • randomlySelect

        public static int randomlySelect​(int[] array,
                                         int streamNum)
        Randomly select an element from the array
        Parameters:
        array - the array to select from
        streamNum - the stream number from the stream provider to use
        Returns:
        the randomly selected value
      • randomlySelect

        public static int randomlySelect​(int[] array,
                                         RNStreamIfc rng)
        Randomly select an element from the array
        Parameters:
        array - the array to select from
        rng - the source of randomness
        Returns:
        the randomly selected value
      • randomlySelect

        public static double randomlySelect​(double[] array)
        Randomly select an element from the array
        Parameters:
        array - the array to select from
        Returns:
        the randomly selected value
      • randomlySelect

        public static double randomlySelect​(double[] array,
                                            int streamNum)
        Randomly select an element from the array
        Parameters:
        array - the array to select from
        streamNum - the stream number from the stream provider to use
        Returns:
        the randomly selected value
      • randomlySelect

        public static double randomlySelect​(double[] array,
                                            RNStreamIfc rng)
        Randomly select an element from the array
        Parameters:
        array - the array to select from
        rng - the source of randomness
        Returns:
        the randomly selected value
      • randomlySelect

        public static double randomlySelect​(double[] array,
                                            double[] cdf)
        Randomly selects from the array using the supplied cdf
        Parameters:
        array - array to select from
        cdf - the cumulative probability associated with each element of array
        Returns:
        the randomly selected value
      • randomlySelect

        public static double randomlySelect​(double[] array,
                                            double[] cdf,
                                            int streamNum)
        Randomly selects from the array using the supplied cdf
        Parameters:
        array - array to select from
        cdf - the cumulative probability associated with each element of array
        streamNum - the stream number from the stream provider to use
        Returns:
        the randomly selected value
      • randomlySelect

        public static double randomlySelect​(double[] array,
                                            double[] cdf,
                                            RNStreamIfc rng)
        Randomly selects from the array using the supplied cdf
        Parameters:
        array - array to select from
        cdf - the cumulative probability associated with each element of array
        rng - the source of randomness
        Returns:
        the randomly selected value
      • randomlySelect

        public static int randomlySelect​(int[] array,
                                         double[] cdf)
        Randomly selects from the array using the supplied cdf
        Parameters:
        array - array to select from
        cdf - the cumulative probability associated with each element of array
        Returns:
        the randomly selected value
      • randomlySelect

        public static int randomlySelect​(int[] array,
                                         double[] cdf,
                                         int streamNum)
        Randomly selects from the array using the supplied cdf
        Parameters:
        array - array to select from
        cdf - the cumulative probability associated with each element of array
        streamNum - the stream number from the stream provider to use
        Returns:
        the randomly selected value
      • randomlySelect

        public static int randomlySelect​(int[] array,
                                         double[] cdf,
                                         RNStreamIfc rng)
        Randomly selects from the array using the supplied cdf
        Parameters:
        array - array to select from
        cdf - the cumulative probability associated with each element of array
        rng - the source of randomness
        Returns:
        the randomly selected value
      • randomlySelect

        public static <T> T randomlySelect​(java.util.List<T> list,
                                           double[] cdf)
        Randomly selects from the list using the supplied cdf
        Type Parameters:
        T - the type returned
        Parameters:
        list - list to select from
        cdf - the cumulative probability associated with each element of array
        Returns:
        the randomly selected value
      • randomlySelect

        public static <T> T randomlySelect​(java.util.List<T> list,
                                           double[] cdf,
                                           int streamNum)
        Randomly selects from the list using the supplied cdf
        Type Parameters:
        T - the type returned
        Parameters:
        list - list to select from
        cdf - the cumulative probability associated with each element of array
        streamNum - the stream number from the stream provider to use
        Returns:
        the randomly selected value
      • randomlySelect

        public static <T> T randomlySelect​(java.util.List<T> list,
                                           double[] cdf,
                                           RNStreamIfc rng)
        Randomly selects from the list using the supplied cdf
        Type Parameters:
        T - the type returned
        Parameters:
        list - list to select from
        cdf - the cumulative probability associated with each element of array
        rng - the source of randomness
        Returns:
        the randomly selected value
      • isValidCDF

        public static boolean isValidCDF​(double[] cdf)
        Parameters:
        cdf - the probability array. must have valid probability elements and last element equal to 1. Every element must be greater than or equal to the previous element. That is, monotonically increasing.
        Returns:
        true if valid cdf
      • isValidPMF

        public static boolean isValidPMF​(double[] prob)
        Each element must be in (0,1) and sum of elements must be less than or equal to 1.0
        Parameters:
        prob - the array to check, must not be null, must have at least two elements
        Returns:
        true if the array represents a probability mass function
      • makeCDF

        public static double[] makeCDF​(double[] prob)
        Parameters:
        prob - the array representing a PMF
        Returns:
        a valid CDF
      • randomlySelect

        public static <T> T randomlySelect​(java.util.List<T> list)
        Randomly select from the list using the default stream
        Type Parameters:
        T - The type of element in the list
        Parameters:
        list - the list
        Returns:
        the randomly selected element
      • randomlySelect

        public static <T> T randomlySelect​(java.util.List<T> list,
                                           int streamNum)
        Randomly select from the list
        Type Parameters:
        T - The type of element in the list
        Parameters:
        list - the list
        streamNum - the stream number from the stream provider to use
        Returns:
        the randomly selected element
      • randomlySelect

        public static <T> T randomlySelect​(java.util.List<T> list,
                                           RNStreamIfc rng)
        Randomly select from the list
        Type Parameters:
        T - The type of element in the list
        Parameters:
        list - the list
        rng - the source of randomness
        Returns:
        the randomly selected element
      • permutation

        public static void permutation​(double[] x)
        Randomly permutes the supplied array using the default random number generator. The array is changed.
        Parameters:
        x - the array
      • permutation

        public static void permutation​(double[] x,
                                       int streamNum)
        Randomly permutes the supplied array using the supplied random number generator, the array is changed
        Parameters:
        x - the array
        streamNum - the stream number from the stream provider to use
      • permutation

        public static void permutation​(double[] x,
                                       RNStreamIfc rng)
        Randomly permutes the supplied array using the supplied random number generator, the array is changed
        Parameters:
        x - the array
        rng - the source of randomness
      • sampleWithoutReplacement

        public static void sampleWithoutReplacement​(double[] x,
                                                    int sampleSize)
        The array x is changed, such that the first sampleSize elements contain the sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement using the default random number generator
        Parameters:
        x - the array
        sampleSize - the size of the generate
      • sampleWithoutReplacement

        public static void sampleWithoutReplacement​(double[] x,
                                                    int sampleSize,
                                                    int streamNum)
        The array x is changed, such that the first sampleSize elements contain the sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement
        Parameters:
        x - the array
        sampleSize - the generate size
        streamNum - the stream number from the stream provider to use
      • sampleWithoutReplacement

        public static void sampleWithoutReplacement​(double[] x,
                                                    int sampleSize,
                                                    RNStreamIfc rng)
        The array x is changed, such that the first sampleSize elements contain the sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement
        Parameters:
        x - the array
        sampleSize - the generate size
        rng - the source of randomness
      • copyFirstNValues

        public static double[] copyFirstNValues​(double[] x,
                                                int n)
        Facilitates sampling without replacement to a new array. Example usage:

        sampleWithoutReplacement(x, 5); // first sample into first 5 slots double[] sample = copyFirstNValues(x, 5); // now copy from the first 5 slots

        Parameters:
        x - the array to copy from
        n - the number of values to copy
        Returns:
        a new array with the values
      • permutation

        public static void permutation​(int[] x)
        Randomly permutes the supplied array using the default random number generator. The array is changed.
        Parameters:
        x - the array
      • permutation

        public static void permutation​(int[] x,
                                       int streamNum)
        Randomly permutes the supplied array using the supplied random number generator, the array is changed.
        Parameters:
        x - the array
        streamNum - the stream number from the stream provider to use
      • permutation

        public static void permutation​(int[] x,
                                       RNStreamIfc rng)
        Randomly permutes the supplied array using the supplied random number generator, the array is changed.
        Parameters:
        x - the array
        rng - the source of randomness
      • sampleWithoutReplacement

        public static void sampleWithoutReplacement​(int[] x,
                                                    int sampleSize)
        The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement using the default random number generator
        Parameters:
        x - the array
        sampleSize - the generate size
      • sampleWithoutReplacement

        public static void sampleWithoutReplacement​(int[] x,
                                                    int sampleSize,
                                                    int streamNum)
        The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement
        Parameters:
        x - the array
        sampleSize - the generate size
        streamNum - the stream number from the stream provider to use
      • sampleWithoutReplacement

        public static void sampleWithoutReplacement​(int[] x,
                                                    int sampleSize,
                                                    RNStreamIfc rng)
        The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement
        Parameters:
        x - the array
        sampleSize - the generate size
        rng - the source of randomness
      • permutation

        public static void permutation​(boolean[] x)
        Randomly permutes the supplied array using the default random number generator. The array is changed.
        Parameters:
        x - the array
      • permutation

        public static void permutation​(boolean[] x,
                                       int streamNum)
        Randomly permutes the supplied array using the supplied random number generator, the array is changed.
        Parameters:
        x - the array
        streamNum - the stream number from the stream provider to use
      • permutation

        public static void permutation​(boolean[] x,
                                       RNStreamIfc rng)
        Randomly permutes the supplied array using the supplied random number generator, the array is changed.
        Parameters:
        x - the array
        rng - the source of randomness
      • sampleWithoutReplacement

        public static void sampleWithoutReplacement​(boolean[] x,
                                                    int sampleSize)
        The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement using the default random number generator
        Parameters:
        x - the array
        sampleSize - the generate size
      • sampleWithoutReplacement

        public static void sampleWithoutReplacement​(boolean[] x,
                                                    int sampleSize,
                                                    int streamNum)
        The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement
        Parameters:
        x - the array
        sampleSize - the generate size
        streamNum - the stream number from the stream provider to use
      • sampleWithoutReplacement

        public static void sampleWithoutReplacement​(boolean[] x,
                                                    int sampleSize,
                                                    RNStreamIfc rng)
        The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the random sample without replacement
        Parameters:
        x - the array
        sampleSize - the generate size
        rng - the source of randomness
      • permutation

        public static <T> void permutation​(T[] x)
        Randomly permutes the supplied array using the default random number generator. The array is changed
        Parameters:
        x - the array
      • permutation

        public static <T> void permutation​(T[] x,
                                           int streamNum)
        Randomly permutes the supplied array using the supplied random number generator, the array is changed
        Parameters:
        x - the array
        streamNum - the stream number from the stream provider to use
      • permutation

        public static <T> void permutation​(T[] x,
                                           RNStreamIfc rng)
        Randomly permutes the supplied array using the supplied random number generator, the array is changed
        Parameters:
        x - the array
        rng - the source of randomness
      • sampleWithoutReplacement

        public static <T> void sampleWithoutReplacement​(T[] x,
                                                        int sampleSize)
        The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the randomly sampled values without replacement using the default random number generator
        Parameters:
        x - the array
        sampleSize - the source of randomness
      • sampleWithoutReplacement

        public static <T> void sampleWithoutReplacement​(T[] x,
                                                        int sampleSize,
                                                        int streamNum)
        The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the randomly sampled values without replacement
        Parameters:
        x - the array
        sampleSize - the generate size
        streamNum - the stream number from the stream provider to use
      • sampleWithoutReplacement

        public static <T> void sampleWithoutReplacement​(T[] x,
                                                        int sampleSize,
                                                        RNStreamIfc rng)
        The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x[0], x[1], ... , x[sampleSize-1] is the randomly sampled values without replacement
        Parameters:
        x - the array
        sampleSize - the generate size
        rng - the source of randomness
      • permutation

        public static <T> void permutation​(java.util.List<T> x)
        Randomly permutes the supplied List using the supplied random number generator, the list is changed
        Type Parameters:
        T - the type of the list
        Parameters:
        x - the list
      • permutation

        public static <T> void permutation​(java.util.List<T> x,
                                           int streamNum)
        Randomly permutes the supplied List using the supplied random number generator, the list is changed
        Type Parameters:
        T - the type of the list
        Parameters:
        x - the list
        streamNum - the stream number from the stream provider to use
      • permutation

        public static <T> void permutation​(java.util.List<T> x,
                                           RNStreamIfc rng)
        Randomly permutes the supplied List using the supplied random number generator, the list is changed
        Type Parameters:
        T - the type of the list
        Parameters:
        x - the list
        rng - the source of randomness
      • sampleWithoutReplacement

        public static <T> void sampleWithoutReplacement​(java.util.List<T> x,
                                                        int sampleSize)
        The List x is changed, such that the first sampleSize elements contain the generate. That is, x.get(0), x.get(1), ... , x.get(sampleSize-1) is the random sample without replacement using the default random number generator
        Type Parameters:
        T - the type of the list
        Parameters:
        x - the list
        sampleSize - the generate size
      • sampleWithoutReplacement

        public static <T> void sampleWithoutReplacement​(java.util.List<T> x,
                                                        int sampleSize,
                                                        int streamNum)
        The List x is changed, such that the first sampleSize elements contain the generate. That is, x.get(0), x.get(1), ... , x.get(sampleSize-1) is the random sample without replacement
        Type Parameters:
        T - the type of the list
        Parameters:
        x - the list
        sampleSize - the generate size
        streamNum - the stream number from the stream provider to use
      • sampleWithoutReplacement

        public static <T> void sampleWithoutReplacement​(java.util.List<T> x,
                                                        int sampleSize,
                                                        RNStreamIfc rng)
        The List x is changed, such that the first sampleSize elements contain the generate. That is, x.get(0), x.get(1), ... , x.get(sampleSize-1) is the random sample without replacement
        Type Parameters:
        T - the type of the list
        Parameters:
        x - the list
        sampleSize - the generate size
        rng - the source of randomness