|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.Random
edu.unm.cs.cs351.tdrl.f07.p2.XRandom
public class XRandom
A small extension of java.util.Random, providing a couple of handy methods Random is missing.
| Field Summary | |
|---|---|
static long |
serialVersionUID
|
| Constructor Summary | |
|---|---|
XRandom()
Create an XRandom initialized with a randomly-chosen seed, so results will tend to differ from run to run even if nothing else changes. |
|
XRandom(long seed)
Create an XRandom initialized with the specified seed, so results will remain identical from run to run -- so long as the same seed is used, and all other random objects and methods (such as Math.random()) are scrupulously avoided. |
|
| Method Summary | ||
|---|---|---|
int |
drawFromCDF(double[] cdf)
Draws an index from an arbitrary (discrete) CDF. |
|
int |
drawFromPMF(double[] pmf)
Draws a value from a discrete probability mass function (PMF) and returns the corresponding outcome. |
|
|
drawFromPMF(Map<T,Double> pmf)
Draws a value from a discrete probability mass function (PMF) and returns the corresponding outcome. |
|
double |
nextExponential(double mean)
Draw a sample from an exponentially distributed random variable with the given mean value. |
|
int |
nextGeometric(double p)
Draw a sample from a geometric distribution with parameter p. |
|
boolean |
nextProbability(double probability)
Return true at random the specified fraction of the time. |
|
| Methods inherited from class java.util.Random |
|---|
next, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeed |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long serialVersionUID
| Constructor Detail |
|---|
public XRandom()
public XRandom(long seed)
seed - the seed to initialize the generator with.| Method Detail |
|---|
public double nextExponential(double mean)
mean - the specified average value of the produced numbers
IllegalArgumentException - if the mean is equal to zeropublic int nextGeometric(double p)
p - Parameter of the geometric distribution.
IllegalArgumentException - if p is not a
probability (i.e., if p<0.0 || p>1.0).public boolean nextProbability(double probability)
probability - the chance of returning true
IllegalArgumentException - if probability is less than 0.0 or
greater than 1.0public int drawFromCDF(double[] cdf)
The contents of the array are assumed to be CDF values, sorted in increasing order. That is, it is required that:
cdf[j]>=cdf[i] for all j>i cdf[cdf.length-1]==1.0If violations of these conditions are detected, an
IllegalStateException is generated.
cdf - Array containing conditional distribution function
data
IllegalStateException - if cdf appears to be
non-normalized.public <T> T drawFromPMF(Map<T,Double> pmf)
Map from the outcome space
onto probabilities. It is required that:
>=0.0
1.0.
If a violation of
these conditions is detected, this throws a
IllegalStateException.
T - Type of the outcome spacepmf - Map from outcome space (T) onto
probabilities.
IllegalStateException - if the pmf is not properly
normalized.public int drawFromPMF(double[] pmf)
>=0.0
1.0.
If a violation of
these conditions is detected, this throws a
IllegalStateException.
pmf - Array of probability values for each index
IllegalStateException - if the pmf is not properly
normalized.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||