public final class StdRandom extends 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 .5, and false otherwise.
|
static boolean |
bernoulli(double p)
Returns a boolean, which is true with probability p, and false otherwise.
|
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()
Returns the seed of the psedurandom number generator.
|
static void |
main(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)
Return an integer with a Poisson distribution with mean lambda.
|
static double |
random()
Deprecated.
clearer to use
uniform() |
static void |
setSeed(long s)
Sets the seed of the psedurandom number generator.
|
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(Object[] a)
Rearrange the elements of an array in random order.
|
static void |
shuffle(Object[] a,
int lo,
int hi)
Rearrange the elements of the subarray a[lo..hi] in random order.
|
static double |
uniform()
Return real number uniformly in [0, 1).
|
static double |
uniform(double a,
double b)
Returns a real number uniformly in [a, b).
|
static int |
uniform(int N)
Returns an integer uniformly between 0 (inclusive) and N (exclusive).
|
static int |
uniform(int a,
int b)
Returns an integer uniformly in [a, b).
|
public static void setSeed(long s)
public static long getSeed()
public static double uniform()
public static int uniform(int N)
IllegalArgumentException - if N <= 0@Deprecated public static double random()
uniform()public static int uniform(int a,
int b)
IllegalArgumentException - if b <= aIllegalArgumentException - if b - a >= Integer.MAX_VALUEpublic static double uniform(double a,
double b)
IllegalArgumentException - if b <= apublic static boolean bernoulli(double p)
IllegalArgumentException - if either p < 0.0 or p > 1.0public static boolean bernoulli()
public static double gaussian()
public static double gaussian(double mean,
double stddev)
public static int geometric(double p)
IllegalArgumentException - if either p < 0.0 or p > 1.0public static int poisson(double lambda)
IllegalArgumentException - if lambda <= 0.0public static double pareto(double alpha)
IllegalArgumentException - if alpha <= 0.0public static double cauchy()
public static int discrete(double[] a)
public static double exp(double lambda)
IllegalArgumentException - if lambda <= 0.0public static void shuffle(Object[] a)
public static void shuffle(double[] a)
public static void shuffle(int[] a)
public static void shuffle(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(String[] args)
Copyright © 2014. All Rights Reserved.