Documentation of 'mikera.util.Rand' Java class
Rand
mikera.util

Class Rand



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

      Constructors 
      Constructor and Description
      Rand() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static int best(int r, int n, int s)
      sum of best r from n s-sided dice
      static double binary(double mean) 
      static void binarySample(double[] temp, int offset, int length)
      Randomises the temp array to 0.0 or 1.0 according to the probabilities in the array
      static void binarySample(float[] temp, int offset, int length) 
      static double binomialChance(int r, int n, double p) 
      static boolean chance(double d)
      Returns true with a given probability
      static boolean chance(float d)
      Returns true with a given probability
      static void chooseIntegers(int[] dest, int destOffset, int length, int maxValue)
      Chooses a set of distinct integers from a range 0 to maxValue-1 Resulting integers are sorted
      static double combinations(int r, int n) 
      static double cumulativeBinomialChance(int r, int n, double p)
      Returns the probability of up to r successes in n trials, each with probability of success p
      static int d(int sides)
      simulates a dice roll with the given number of sides
      static int d(int number, int sides)
      Calculates the sum of (number) x (sides)-sided dice
      static int d10() 
      static int d100() 
      static int d12() 
      static int d20() 
      static int d3() 
      static int d4() 
      static int d6() 
      static int d8() 
      static double exp(double mean)
      Returns a random sample from an exponential distribution
      static double factorial(int n) 
      static double factorialRatio(int n, int r)
      Calculates n!/r! Avoids the overhead of calculating the terms which cancel out
      static void fillBinary(double[] data, int start, int length, double mean) 
      static void fillBinary(float[] d, int start, int length) 
      static void fillGaussian(double[] d, int start, int length, double u, double sd) 
      static void fillGaussian(float[] d, int start, int length, float u, float sd) 
      static void fillUniform(float[] d, int start, int length) 
      static int geom(double p)
      Returns a sample from a Geometric distribution Discrete distribution with decay rate p Mean = (1-p) / p Probability mass function for each integer output k = p.(1-p)^k
      static int indexFromWeights(double[] probabilities) 
      static double n(double u, double sd)
      Generates a normal distributed number with the given mean and standard deviation
      static boolean nextBoolean()
      Sample a random boolean value with 50% chance
      static byte nextByte()
      Sample a random (signed) byte
      static char nextChar()
      Sample a random char
      static double nextDouble()
      Returns standard double in range [0..1)
      static float nextFloat()
      Sample a random float in range [0..1)
      static double nextGaussian() 
      static int nextInt()
      Sample a random signed 32-bit integer
      static char nextLetter()
      Sample a random lowercase letter
      static java.lang.String nextLetterString(int length) 
      static long nextLong()
      Gets a long random value
      static short nextShort()
      Sample a random signed short value
      static java.lang.String nextString() 
      static int otherIndex(int i, int max)
      Return a random index between 0 and max (exclusive) not equal to i
      static <T> T pick(java.util.Collection<T> ts)
      Picks a random item from a given collection
      static <T> T pick(java.util.List<T> ts)
      Picks a random item from a given list
      static <T> T pick(T[] ts)
      Picks a random item from a given array
      static int po(double mean)
      Poisson distribution
      static int po(int numerator, int denominator)
      Draw a sample from the possion distribution with parameter = numerator / denominator
      static int r(int s)
      Random number from zero to s-1
      static void randIntegers(int[] dest, int destOffset, int length, int maxValue)
      Creates a set of n random integers from a range of 0 to maxValue-1
      static int range(int n1, int n2)
      Returns random number uniformly distributed in inclusive [n1, n2] range.
      static int round(double d)
      Randomly rounds to the nearest integer
      static <T> void shuffle(T[] ts)
      Randomly shuffles all elements in a given array
      static int sig(float x)
      logistic sigmoid probability
      static double sigmoid(double a)
      Sigmoid function
      static double u()
      Sample a random uniform double in range [0..1)
      static double u(double max)
      Sample a random uniform double in range [0..max)
      static double u(double min, double max)
      Sample a random uniform double in the range [min..max)
      static int xorShift32(int a)
      XORShift algorithm - credit to George Marsaglia!
      static long xorShift64(long a)
      XORShift algorithm - very fast psuedo-random number generator Credit to George Marsaglia!
      • Methods inherited from class java.lang.Object

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

      • Rand

        public Rand()
    • Method Detail

      • nextLong

        public static final long nextLong()
        Gets a long random value
        Returns:
        Random long value based on static state
      • xorShift64

        public static final long xorShift64(long a)
        XORShift algorithm - very fast psuedo-random number generator Credit to George Marsaglia!
        Parameters:
        a - Initial state
        Returns:
        new state
      • xorShift32

        public static final int xorShift32(int a)
        XORShift algorithm - credit to George Marsaglia!
        Parameters:
        a - Initial state
        Returns:
        new state
      • chance

        public static boolean chance(double d)
        Returns true with a given probability
        Parameters:
        d -
        Returns:
      • chance

        public static boolean chance(float d)
        Returns true with a given probability
        Parameters:
        d -
        Returns:
      • best

        public static int best(int r,
                               int n,
                               int s)
        sum of best r from n s-sided dice
        Parameters:
        r -
        n -
        s -
        Returns:
      • sigmoid

        public static double sigmoid(double a)
        Sigmoid function
      • sig

        public static int sig(float x)
        logistic sigmoid probability
        Parameters:
        x -
        Returns:
      • po

        public static int po(double mean)
        Poisson distribution
        Parameters:
        mean - The mean of the poisson distrubution to sample from
        Returns:
      • po

        public static int po(int numerator,
                             int denominator)
        Draw a sample from the possion distribution with parameter = numerator / denominator
        Parameters:
        numerator -
        denominator -
        Returns:
      • d

        public static int d(int number,
                            int sides)
        Calculates the sum of (number) x (sides)-sided dice
        Parameters:
        number -
        sides -
        Returns:
      • factorial

        public static double factorial(int n)
      • factorialRatio

        public static double factorialRatio(int n,
                                            int r)
        Calculates n!/r! Avoids the overhead of calculating the terms which cancel out
        Parameters:
        n -
        r -
        Returns:
      • cumulativeBinomialChance

        public static double cumulativeBinomialChance(int r,
                                                      int n,
                                                      double p)
        Returns the probability of up to r successes in n trials, each with probability of success p
        Parameters:
        r -
        n -
        p -
        Returns:
      • combinations

        public static double combinations(int r,
                                          int n)
      • binomialChance

        public static double binomialChance(int r,
                                            int n,
                                            double p)
      • exp

        public static double exp(double mean)
        Returns a random sample from an exponential distribution
        Parameters:
        mean -
        Returns:
      • geom

        public static int geom(double p)
        Returns a sample from a Geometric distribution Discrete distribution with decay rate p Mean = (1-p) / p Probability mass function for each integer output k = p.(1-p)^k
      • nextInt

        public static final int nextInt()
        Sample a random signed 32-bit integer
        Returns:
      • nextShort

        public static final short nextShort()
        Sample a random signed short value
        Returns:
      • nextChar

        public static final char nextChar()
        Sample a random char
        Returns:
      • nextLetterString

        public static final java.lang.String nextLetterString(int length)
      • nextByte

        public static final byte nextByte()
        Sample a random (signed) byte
        Returns:
      • nextBoolean

        public static boolean nextBoolean()
        Sample a random boolean value with 50% chance
        Returns:
      • nextLetter

        public static final char nextLetter()
        Sample a random lowercase letter
        Returns:
      • r

        public static final int r(int s)
        Random number from zero to s-1
        Parameters:
        s - Upper bound (excluded)
        Returns:
      • otherIndex

        public static final int otherIndex(int i,
                                           int max)
        Return a random index between 0 and max (exclusive) not equal to i
      • nextDouble

        public static final double nextDouble()
        Returns standard double in range [0..1)
        Returns:
      • nextFloat

        public static final float nextFloat()
        Sample a random float in range [0..1)
        Returns:
      • u

        public static final double u()
        Sample a random uniform double in range [0..1)
        Returns:
      • u

        public static final double u(double max)
        Sample a random uniform double in range [0..max)
        Parameters:
        max -
        Returns:
      • u

        public static final double u(double min,
                                     double max)
        Sample a random uniform double in the range [min..max)
        Parameters:
        min -
        max -
        Returns:
      • round

        public static final int round(double d)
        Randomly rounds to the nearest integer
      • range

        public static final int range(int n1,
                                      int n2)
        Returns random number uniformly distributed in inclusive [n1, n2] range. It is allowed to have to n1 > n2, or n1 < n2, or n1 == n2.
      • d

        public static final int d(int sides)
        simulates a dice roll with the given number of sides
        Parameters:
        sides -
        Returns:
      • d3

        public static final int d3()
      • d4

        public static final int d4()
      • d6

        public static final int d6()
      • d8

        public static final int d8()
      • d10

        public static final int d10()
      • d12

        public static final int d12()
      • d20

        public static final int d20()
      • d100

        public static final int d100()
      • n

        public static double n(double u,
                               double sd)
        Generates a normal distributed number with the given mean and standard deviation
        Parameters:
        u - Mean
        sd - Standard deviation
        Returns:
      • nextGaussian

        public static double nextGaussian()
      • nextString

        public static java.lang.String nextString()
      • shuffle

        public static <T> void shuffle(T[] ts)
        Randomly shuffles all elements in a given array
      • chooseIntegers

        public static void chooseIntegers(int[] dest,
                                          int destOffset,
                                          int length,
                                          int maxValue)
        Chooses a set of distinct integers from a range 0 to maxValue-1 Resulting integers are sorted
      • randIntegers

        public static void randIntegers(int[] dest,
                                        int destOffset,
                                        int length,
                                        int maxValue)
        Creates a set of n random integers from a range of 0 to maxValue-1
      • pick

        public static <T> T pick(T[] ts)
        Picks a random item from a given array
      • pick

        public static <T> T pick(java.util.List<T> ts)
        Picks a random item from a given list
      • pick

        public static <T> T pick(java.util.Collection<T> ts)
        Picks a random item from a given collection
      • fillUniform

        public static void fillUniform(float[] d,
                                       int start,
                                       int length)
      • fillBinary

        public static void fillBinary(float[] d,
                                      int start,
                                      int length)
      • fillGaussian

        public static void fillGaussian(float[] d,
                                        int start,
                                        int length,
                                        float u,
                                        float sd)
      • fillGaussian

        public static void fillGaussian(double[] d,
                                        int start,
                                        int length,
                                        double u,
                                        double sd)
      • fillBinary

        public static void fillBinary(double[] data,
                                      int start,
                                      int length,
                                      double mean)
      • binary

        public static double binary(double mean)
      • binarySample

        public static void binarySample(float[] temp,
                                        int offset,
                                        int length)
      • binarySample

        public static void binarySample(double[] temp,
                                        int offset,
                                        int length)
        Randomises the temp array to 0.0 or 1.0 according to the probabilities in the array
        Parameters:
        temp -
        offset -
        length -
      • indexFromWeights

        public static int indexFromWeights(double[] probabilities)

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.