public class Randoms
extends java.lang.Object
| Constructor and Description |
|---|
Randoms() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
bernoulli()
Return a boolean, which is true with probability .5, and false otherwise.
|
static boolean |
bernoulli(double p)
Return a boolean, which is true with probability p, and false otherwise.
|
static double |
cauchy()
Return a real number with a Cauchy distribution.
|
static void |
clearCache() |
static int |
discrete(double[] a)
Return a number from a discrete distribution: i with probability a[i].
|
static double[] |
doubles(double min,
double max,
int size)
A random double array with values in [min, max).
|
static double[] |
doubles(int size)
A random double array with values in [0, 1)
|
static double |
exp(double lambda)
Return a real number from an exponential distribution with rate lambda.
|
static double |
gamma(double alpha,
double scale)
Randomly sample 1 point from Gamma Distribution with the given parameters.
|
static double |
gaussian(double mu,
double sigma)
Return a real number from a Gaussian distribution with given mean and stddev.
|
static int[] |
indexs(int size,
int min,
int max)
Generate no repeat
size indexes from min to max |
static int[] |
ints(int range,
int size) |
static int[] |
ints(int min,
int max,
int size) |
static java.util.List<java.lang.Double> |
list(int size) |
static java.util.List<java.lang.Double> |
list(int size,
int min,
int max) |
static java.util.List<java.lang.Double> |
list(int size,
int min,
int max,
boolean isInteger) |
static int |
nextInt(int range,
int... exceptions)
generate next random integer in a range besides exceptions
|
static int |
nextInt(int min,
int max,
int... exceptions)
generate next random integer in a range [min, max) besides exceptions
|
static int[] |
nextIntArray(int length,
int range)
generate next integers array with no repeated elements
|
static int[] |
nextIntArray(int length,
int range,
int... exceptions) |
static int[] |
nextIntArray(int length,
int min,
int max) |
static int[] |
nextIntArray(int length,
int min,
int max,
int... exceptions) |
static double |
pareto(double alpha)
Return a real number with a Pareto distribution with parameter alpha.
|
static java.util.List<java.lang.Integer> |
permute(int min,
int max)
Generate a permutation from min to max
|
static int |
poisson(double lambda)
Return an integer with a Poisson distribution with mean lambda.
|
static java.util.List<java.lang.Integer> |
randInts(int length,
int min,
int max)
Generate a set of random (unique) integers in the range [min, max) with length
length |
static double |
random()
Return real number uniformly in [0, 1).
|
static <T> T |
random(java.util.List<T> data)
Return a random number from a given list of numbers.
|
static double[] |
randProbs(int size)
Get a normalize array of probabilities
|
static void |
seed(long seed) |
static double |
uniform()
Random (uniformly distributed) double in [0, 1)
|
static double |
uniform(double min,
double max)
Random (uniformly distributed) double in [min, max)
|
static int |
uniform(int range)
Random generate an integer in [0, range)
|
static int |
uniform(int min,
int max)
Random generate an integer in [min, max)
|
static DenseMatrix |
wishart(DenseMatrix scale,
double df)
Randomly sample a matrix from Wishart Distribution with the given parameters.
|
public static int uniform(int range)
range - range of the intervalpublic static void seed(long seed)
public static int uniform(int min,
int max)
min - minimum of the rangemax - maximum of the rangepublic static double random()
public static <T> T random(java.util.List<T> data)
T - type parameterdata - a given list of numberspublic static double[] doubles(int size)
size - the size of random arraypublic static double[] doubles(double min,
double max,
int size)
min - minimummax - maximumsize - the size of random arraypublic static double uniform()
public static double uniform(double min,
double max)
max - max of the rangemin - min of the rangepublic static boolean bernoulli(double p)
p - probability ppublic static boolean bernoulli()
public static double gaussian(double mu,
double sigma)
mu - meansigma - stddevpublic static double gamma(double alpha,
double scale)
alpha - alpha parameter for Gamma Distribution.scale - scale parameter for Gamma Distribution.public static DenseMatrix wishart(DenseMatrix scale, double df) throws LibrecException
scale - scale parameter for Wishart Distribution.df - degree of freedom for Wishart Distribution.LibrecException - if error occurspublic static int poisson(double lambda)
lambda - mean lambdapublic static double pareto(double alpha)
alpha - parameter alphapublic static double cauchy()
public static int discrete(double[] a)
a - probability a[i]public static double exp(double lambda)
lambda - rate lambdapublic static int nextInt(int range,
int... exceptions)
range - the range located of next integerexceptions - the exception values when generating integers, sorted firstpublic static int nextInt(int min,
int max,
int... exceptions)
min - the minimum of rangemax - the maximum of rangeexceptions - the exception values when generating integers, sorted firstpublic static int[] indexs(int size,
int min,
int max)
size indexes from min to maxmin - min of the rangemax - max of the rangesize - size of the index arraysize indexes from min to maxpublic static void clearCache()
public static int[] nextIntArray(int length,
int range)
throws java.lang.Exception
length - the length of the arrayrange - the index range of the array, default [0, range)java.lang.Exception - if the range is less than length, an exception will be thrownpublic static int[] nextIntArray(int length,
int range,
int... exceptions)
throws java.lang.Exception
java.lang.Exceptionpublic static int[] nextIntArray(int length,
int min,
int max)
throws java.lang.Exception
java.lang.Exceptionpublic static int[] nextIntArray(int length,
int min,
int max,
int... exceptions)
throws java.lang.Exception
java.lang.Exceptionpublic static java.util.List<java.lang.Integer> randInts(int length,
int min,
int max)
throws java.lang.Exception
lengthmax - max of the rangemin - min of the rangelength - length of the Listjava.lang.Exception - if error occurspublic static double[] randProbs(int size)
size - array sizepublic static int[] ints(int range,
int size)
public static int[] ints(int min,
int max,
int size)
public static java.util.List<java.lang.Double> list(int size)
public static java.util.List<java.lang.Double> list(int size,
int min,
int max)
public static java.util.List<java.lang.Double> list(int size,
int min,
int max,
boolean isInteger)
public static java.util.List<java.lang.Integer> permute(int min,
int max)
min - the minimum valuemax - the maximum valueCopyright © 2017. All Rights Reserved.