|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.cornell.lassp.houle.RngPack.RandomElement
RandomElement is an abstract class that encapsulates random number
generators. To base a class on it, you must define the method
raw()
as described below. It is also likely that you
will want to define a constructor or another mechanism for seeding the
the generator. The other classes defined in RandomElement
add value to the numbers generated by raw()
Source code is available.
RandomJava
,
RandomShuffle
Constructor Summary | |
RandomElement()
|
Method Summary | |
int |
choose(int hi)
|
int |
choose(int lo,
int hi)
|
Object |
clone()
|
boolean |
coin()
|
boolean |
coin(double p)
|
double |
gaussian()
gaussian() uses the Box-Muller algorithm to transform raw()'s into gaussian deviates. |
double |
gaussian(double sd)
|
double |
powlaw(double alpha,
double cut)
generate a power-law distribution with exponent alpha
and lower cutoff
cut
|
abstract double |
raw()
The abstract method that must be defined to make a working RandomElement. |
void |
raw(double[] d)
Fill an entire array with doubles. |
void |
raw(double[] d,
int n)
Fill part or all of an array with doubles. |
double |
uniform(double lo,
double hi)
|
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public RandomElement()
Method Detail |
public abstract double raw()
RandomJava
for an example of how to do this.
RandomJava
public void raw(double[] d, int n)
raw()
to fill the array. You can eliminate the overhead of
multiple method calls by subclassing this with a version of the generator
that fills the array. On our system this improves the efficiency of
Ranecu
by 20% when filling large arrays.
d
- array to be filled with doublesn
- number of doubles to generatepublic void raw(double[] d)
raw(double d[],int n)
with d=d.length
. Since this adds little overhead for d.length
large, it is only necessary to override raw(double d[],int n)
d
- array to be filled with doubles.public int choose(int hi)
hi
- upper limit of range
public int choose(int lo, int hi)
lo
- lower limit of rangehi
- upper limit of range
public boolean coin()
public boolean coin(double p)
p
- probability that function will return true
public double uniform(double lo, double hi)
lo
- lower limit of rangehi
- upper limit of range
public double gaussian()
public double gaussian(double sd)
sd
- standard deviation
public double powlaw(double alpha, double cut)
alpha
and lower cutoff
cut
alpha
- the exponentcut
- the lower cutoffpublic Object clone() throws CloneNotSupportedException
CloneNotSupportedException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |