public final class Rand extends Object
| Constructor and Description |
|---|
Rand() |
| 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 String |
nextLetterString(int length) |
static long |
nextLong()
Gets a long random value
|
static short |
nextShort()
Sample a random signed short value
|
static 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(Collection<T> ts)
Picks a random item from a given collection
|
static <T> T |
pick(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!
|
public static final long nextLong()
public static final long xorShift64(long a)
a - Initial statepublic static final int xorShift32(int a)
a - Initial statepublic static boolean chance(double d)
d - public static boolean chance(float d)
d - public static int best(int r,
int n,
int s)
r - n - s - public static double sigmoid(double a)
public static int sig(float x)
x - public static int po(double mean)
mean - The mean of the poisson distrubution to sample frompublic static int po(int numerator,
int denominator)
numerator - denominator - public static int d(int number,
int sides)
number - sides - public static double factorial(int n)
public static double factorialRatio(int n,
int r)
n - r - public static double cumulativeBinomialChance(int r,
int n,
double p)
r - n - p - public static double combinations(int r,
int n)
public static double binomialChance(int r,
int n,
double p)
public static double exp(double mean)
mean - public static int geom(double p)
public static final int nextInt()
public static final short nextShort()
public static final char nextChar()
public static final String nextLetterString(int length)
public static final byte nextByte()
public static boolean nextBoolean()
public static final char nextLetter()
public static final int r(int s)
s - Upper bound (excluded)public static final int otherIndex(int i,
int max)
public static final double nextDouble()
public static final float nextFloat()
public static final double u()
public static final double u(double max)
max - public static final double u(double min,
double max)
min - max - public static final int round(double d)
public static final int range(int n1,
int n2)
public static final int d(int sides)
sides - public static final int d3()
public static final int d4()
public static final int d6()
public static final int d8()
public static final int d10()
public static final int d12()
public static final int d20()
public static final int d100()
public static double n(double u,
double sd)
u - Meansd - Standard deviationpublic static double nextGaussian()
public static String nextString()
public static <T> void shuffle(T[] ts)
public static void chooseIntegers(int[] dest,
int destOffset,
int length,
int maxValue)
public static void randIntegers(int[] dest,
int destOffset,
int length,
int maxValue)
public static <T> T pick(T[] ts)
public static <T> T pick(List<T> ts)
public static <T> T pick(Collection<T> ts)
public static void fillUniform(float[] d,
int start,
int length)
public static void fillBinary(float[] d,
int start,
int length)
public static void fillGaussian(float[] d,
int start,
int length,
float u,
float sd)
public static void fillGaussian(double[] d,
int start,
int length,
double u,
double sd)
public static void fillBinary(double[] data,
int start,
int length,
double mean)
public static double binary(double mean)
public static void binarySample(float[] temp,
int offset,
int length)
public static void binarySample(double[] temp,
int offset,
int length)
temp - offset - length - public static int indexFromWeights(double[] probabilities)
Copyright © 2012. All Rights Reserved.