|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ignotus.util.RandUtil
public class RandUtil
Implements a few useful random number methods, maintains an internal random number generator. You will only need to instantiate this class if you want to maintain different random number generators (for example, initialized with different seeds).
Constructor Summary | |
---|---|
RandUtil()
|
Method Summary | |
---|---|
double |
calcGauss(double mean,
double variance)
Returns a Gaussian variable using standard algorithm from Crandall, Pascal Applications for the Sciences |
double |
gauss()
Returns a Gaussian variable using Java library call to Random.nextGaussian . |
double |
gauss(double mean,
double variance)
Returns a Gaussian variable using a Java library call to Random.nextGaussian . |
double |
quickGauss()
returns a Gaussian variable using Peitgen and Saupe's algorithm from The Science of Fractal Images |
double |
quickGauss(double mean,
double variance)
returns a quick approximation to a Gaussian variable using Peitgen and Saupe's algorithm from The Science of Fractal Images |
Random |
randGenerator()
Returns the internal random number generator. |
Object |
randomElement(ArrayList arr)
Returns a random element from a raw ArrayList . |
double |
randomElement(double[] arr)
Returns a random double from an array. |
float |
randomElement(float[] arr)
Returns a random float from an array. |
int |
randomElement(int[] arr)
Returns a random int from an array. |
double |
randomInRange(double low,
double high)
Returns a random double in a range from high to low, inclusive. |
float |
randomInRange(float low,
float high)
Returns a random float in a range from high to low, inclusive. |
int |
randomInRange(int low,
int high)
Returns a random int in a range from high to low, inclusive. |
void |
setRandGenerator(Random newRandGenerator)
Sets the internal random number generator to the supplied instance of Random. |
void |
setRandSeed(long seed)
Sets the seed value for the internal random number generator. |
void |
shuffle(ArrayList arr)
Shuffles an ArrayList into random order. |
void |
shuffle(double[] doubleArray)
Shuffles an array of doubles into random order. |
void |
shuffle(float[] floatArray)
Shuffles an array of floats into random order. |
void |
shuffle(int[] intArray)
Shuffles an array of integers into random order. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RandUtil()
Method Detail |
---|
public Random randGenerator()
public void setRandGenerator(Random newRandGenerator)
newRandGenerator
- an instance of Randompublic void setRandSeed(long seed)
seed
- public void shuffle(int[] intArray)
intArray
- an array of int
s, changed on exitpublic void shuffle(float[] floatArray)
floatArray
- an array of float
s, changed on exitpublic void shuffle(double[] doubleArray)
doubleArray
- an array of double
s, changed on exitpublic void shuffle(ArrayList arr)
ArrayList
into random order.
arr
- an ArrayList
, changed on exit
ArrayList is raw, no type checking is done.public int randomInRange(int low, int high)
int
in a range from high to low, inclusive.
low
- lower bound of rangehigh
- upper bound of range
public float randomInRange(float low, float high)
float
in a range from high to low, inclusive.
low
- lower bound of rangehigh
- upper bound of range
public double randomInRange(double low, double high)
double
in a range from high to low, inclusive.
low
- lower bound of rangehigh
- upper bound of range
public int randomElement(int[] arr)
int
from an array.
arr
- an array of int
public float randomElement(float[] arr)
float
from an array.
arr
- an array of float
public double randomElement(double[] arr)
double
from an array.
arr
- an array of double
public Object randomElement(ArrayList arr)
ArrayList
.
arr
- and ArrayList
of untyped objects.
public double gauss()
Random.nextGaussian
.
public double gauss(double mean, double variance)
Random.nextGaussian
.
mean
- variance
-
mean
and variance variance
public double calcGauss(double mean, double variance)
mean
- variance
-
public double quickGauss()
public double quickGauss(double mean, double variance)
mean
- mean value of the distributionvariance
- variance of the distribution
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |