public final class StdRandom extends java.lang.Object
For additional documentation, see Section 2.2 of "Introduction to Programming in Java: An Interdisciplinary Approach" by Robert Sedgewick and Kevin Wayne.
Modifier and Type | Method and Description |
---|---|
static boolean |
bernoulli()
Returns a boolean, which is true with probability 0.5,
and false otherwise.
|
static boolean |
bernoulli(double p)
Returns true with probability p.
|
static double |
cauchy()
Returns a real number with a Cauchy distribution.
|
static int |
discrete(double[] a)
Returns a number from a discrete distribution:
i with probability a[i].
|
static double |
exp(double lambda)
Returns a real number from an exponential distribution
with rate lambda.
|
static double |
gaussian()
Returns a real number with a standard Gaussian distribution.
|
static double |
gaussian(double mean,
double stddev)
Returns a real number from a Gaussian distribution
with given mean and stddev.
|
static int |
geometric(double p)
Returns an integer with a geometric distribution
with mean 1/p.
|
static long |
getSeed()
Get the seed of the pseudorandom number generator.
|
static void |
main(java.lang.String[] args)
Unit test.
|
static double |
pareto(double alpha)
Returns a real number with a Pareto distribution
with parameter alpha.
|
static int |
poisson(double lambda)
Returns an integer with a Poisson distribution
with mean lambda > 0.
|
static double |
random()
Returns real number uniformly in [0, 1).
|
static void |
setSeed(long s)
Define a semente do gerador de números pseudoaleatórios.
|
static void |
shuffle(double[] a)
Rearrange the elements of a double array in random order.
|
static void |
shuffle(double[] a,
int lo,
int hi)
Rearrange the elements of the subarray a[lo..hi]
in random order.
|
static void |
shuffle(int[] a)
Rearrange the elements of an int array in random order.
|
static void |
shuffle(int[] a,
int lo,
int hi)
Rearrange the elements of the subarray a[lo..hi]
in random order.
|
static void |
shuffle(java.lang.Object[] a)
Rearrange the elements of an array in random order.
|
static void |
shuffle(java.lang.Object[] a,
int lo,
int hi)
Rearrange the elements of the subarray a[lo..hi]
in random order.
|
static double |
uniform()
Returns a random real in [0,1).
|
static double |
uniform(double a,
double b)
Returns real number uniformly in [a, b).
|
static int |
uniform(int N)
Random integer in 0..N-1.
|
static int |
uniform(int a,
int b)
Inteiro aleatório em a..b-1.
|
public static void setSeed(long s)
public static long getSeed()
public static double uniform()
public static int uniform(int N)
public static double random()
public static int uniform(int a, int b)
public static double uniform(double a, double b)
public static boolean bernoulli(double p)
public static boolean bernoulli()
public static double gaussian()
public static double gaussian(double mean, double stddev)
public static int geometric(double p)
public static int poisson(double lambda)
public static double pareto(double alpha)
public static double cauchy()
public static int discrete(double[] a)
public static double exp(double lambda)
public static void shuffle(java.lang.Object[] a)
public static void shuffle(double[] a)
public static void shuffle(int[] a)
public static void shuffle(java.lang.Object[] a, int lo, int hi)
public static void shuffle(double[] a, int lo, int hi)
public static void shuffle(int[] a, int lo, int hi)
public static void main(java.lang.String[] args)