edu.stanford.math.plex4.utility
public class RandomUtility extends java.lang.Object
| Constructor and Description |
|---|
RandomUtility() |
| Modifier and Type | Method and Description |
|---|---|
static void |
initializeWithSeed(int seed)
This function initializes the seeds of the random number generators to the specified
values.
|
static int |
nextBernoulli(double p)
This function returns a sample of a Bernoulli random
variable with parameter p.
|
static double |
nextNormal()
This function returns a normal random number.
|
static double |
nextUniform()
This function returns a uniform random number
in the open interval (0, 1).
|
static int |
nextUniformInt(int from,
int to)
Returns a uniformly distributed integer in the inclusive interval
{from, ..., to}
|
static int |
nextUniformIntExcluded(int from,
int to,
int exclusion)
This function returns an integer uniformly distributed
in the set {from, ..., to} \ {exclusion}.
|
static double[] |
normalArray(int length)
This function returns an array of normally distributed
random numbers.
|
static double[] |
normalArray(int length,
boolean normalize)
This function returns an array of normally distributed
random numbers.
|
static double[][] |
normalMatrix(int rows,
int columns)
This function returns a matrix containing normally
distributed random numbers.
|
static int[] |
permute(int[] values)
This function computes a random permutation of the
input array, and then applies the permutation.
|
static gnu.trove.TIntHashSet |
randomSubset(int subsetSize,
int selectionSetSize)
This function computes a random subset of size subsetSize from the
set {0, ..., selectionSetSize - 1}.
|
static double[] |
uniformArray(int length)
This function returns an array of uniformly distributed
random numbers.
|
static double[][] |
uniformMatrix(int rows,
int columns)
This function returns a matrix containing uniformly
distributed random numbers.
|
public static void initializeWithSeed(int seed)
seed - the seed to initialize withpublic static int nextBernoulli(double p)
p - The probability of returning 1public static double nextUniform()
public static double nextNormal()
public static int nextUniformInt(int from,
int to)
from - the start integerto - the end integerpublic static int nextUniformIntExcluded(int from,
int to,
int exclusion)
from - the lowest member of the setto - the highest member of the setexclusion - the member to excludepublic static double[] normalArray(int length,
boolean normalize)
length - the length of the array to createnormalize - whether to normalize the vector or notpublic static double[] uniformArray(int length)
length - the length of the array to createpublic static double[] normalArray(int length)
length - the length of the array to createpublic static double[][] uniformMatrix(int rows,
int columns)
rows - the number of rows in the returned matrixcolumns - the number of columns in the returned matrixpublic static double[][] normalMatrix(int rows,
int columns)
rows - the number of rows in the returned matrixcolumns - the number of columns in the returned matrixpublic static int[] permute(int[] values)
values - the array of integers to permutepublic static gnu.trove.TIntHashSet randomSubset(int subsetSize,
int selectionSetSize)
subsetSize - the size of the subset to returnselectionSetSize - the size of the set to select from