Package HAL
Class Rand
- java.lang.Object
-
- HAL.Rand
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
MultinomialCalc,MultinomialCalcLong
public class Rand extends java.lang.Object implements java.io.Serializablecontains functions for random value generation and distribution sampling.- See Also:
- Serialized Form
-
-
Method Summary
Modifier and Type Method Description intBinomial(int n, double p)returns a random number from the binomial distribution (number of heads from n weighted coin flips with probability p of heads)longBinomial(long n, double p)returns a random number from the binomial distributionbooleanBool()returns a random boolean value (true or false)doubleDouble()returns a random double from 0 to 1doubleDouble(double bound)returns a random double from 0 up to bounddoubleDouble(int bound)doubleExponentialDist(double rate)Samples and exponential distribution with the argument rate parameter equivalent to the timing of the next poisson event with the same rate parameterdoubleGaussian(double mean, double stdDev)returns a random number from the binomial distribution (number of heads from n weighted coin flips with probability p of heads)intInt(int bound)returns a random integer from 0 up to (not including) boundlongLong(long bound)returns a random long from 0 up to (not including) boundvoidMultinomial(double[] probabilities, int n, int[] ret)voidMultinomial(double[] probabilities, long n, long[] ret)voidRandomDS(double[] out, double min, double max)Fills out with random doubles between min and max inclusivevoidRandomIS(int[] out, int min, int max)Fills out with random integers between min (inclusive) and max (exclusive)voidRandomPointInCircle(double radius, double[] ret)voidRandomPointInSphere(double radius, double[] ret)voidRandomPointOnCircleEdge(double radius, double[] ret)gets a random point on the surface of a circle centered at 0,0, with the provided radius.voidRandomPointOnSphereEdge(double radius, double[] ret)gets a random point on the surface of a sphere centered at 0,0,0, with the provided radius.intRandomVariable(double[] probs)Samples a discrete random variable from the probabilities providedintRandomVariable(double[] probs, double rand, int start, int end)intRandomVariable(double[] probs, int start, int end)voidShuffle(double[] arr)voidShuffle(double[] arr, int numberOfShuffles)voidShuffle(double[] arr, int sampleSize, int numberOfShuffles)Shuffles an array of doublesvoidShuffle(int[] arr)voidShuffle(int[] arr, int numberOfShuffles)voidShuffle(int[] arr, int sampleSize, int numberOfShuffles)Shuffles an array of integersvoidShuffle(java.lang.Object[] arr)voidShuffle(java.lang.Object[] arr, int sampleSize, int numberOfShuffles)Shuffles an array of objects
-
-
-
Constructor Detail
-
Rand
public Rand(RNG rng)
creates a Rand object using the RNG argument as its internal generator
-
Rand
public Rand(long seed)
-
Rand
public Rand()
-
-
Method Detail
-
Int
public int Int(int bound)
returns a random integer from 0 up to (not including) bound
-
Double
public double Double(double bound)
returns a random double from 0 up to bound
-
Double
public double Double(int bound)
-
Double
public double Double()
returns a random double from 0 to 1
-
Long
public long Long(long bound)
returns a random long from 0 up to (not including) bound
-
Bool
public boolean Bool()
returns a random boolean value (true or false)
-
Binomial
public long Binomial(long n, double p)returns a random number from the binomial distribution
-
Binomial
public int Binomial(int n, double p)returns a random number from the binomial distribution (number of heads from n weighted coin flips with probability p of heads)
-
Gaussian
public double Gaussian(double mean, double stdDev)returns a random number from the binomial distribution (number of heads from n weighted coin flips with probability p of heads)
-
Multinomial
public void Multinomial(double[] probabilities, int n, int[] ret)
-
Multinomial
public void Multinomial(double[] probabilities, long n, long[] ret)
-
RandomPointOnSphereEdge
public void RandomPointOnSphereEdge(double radius, double[] ret)gets a random point on the surface of a sphere centered at 0,0,0, with the provided radius. the x,y,z coords are put in the double[] ret
-
RandomPointInSphere
public void RandomPointInSphere(double radius, double[] ret)
-
RandomPointOnCircleEdge
public void RandomPointOnCircleEdge(double radius, double[] ret)gets a random point on the surface of a circle centered at 0,0, with the provided radius. the x,y coords are put in the double[] ret
-
RandomPointInCircle
public void RandomPointInCircle(double radius, double[] ret)
-
RandomVariable
public int RandomVariable(double[] probs)
Samples a discrete random variable from the probabilities provided- Parameters:
probs- an array of probabilities. should sum to 1- Returns:
- the index of the probability bin that was sampled
-
RandomVariable
public int RandomVariable(double[] probs, int start, int end)
-
RandomVariable
public int RandomVariable(double[] probs, double rand, int start, int end)
-
RandomDS
public void RandomDS(double[] out, double min, double max)Fills out with random doubles between min and max inclusive- Parameters:
out- the array the random doubles should be written to. the length of the input array defines the number of doubles to be generated
-
RandomIS
public void RandomIS(int[] out, int min, int max)Fills out with random integers between min (inclusive) and max (exclusive)- Parameters:
out- the array the random doubles should be written to. the length of the input array defines the number of doubles to be generated
-
ExponentialDist
public double ExponentialDist(double rate)
Samples and exponential distribution with the argument rate parameter equivalent to the timing of the next poisson event with the same rate parameter
-
Shuffle
public void Shuffle(int[] arr, int sampleSize, int numberOfShuffles)Shuffles an array of integers- Parameters:
arr- array to be shuffledsampleSize- number of elements from array that shuffling can deltasnumberOfShuffles- number of elements that will be shuffled, should not exceed lenToShuffle
-
Shuffle
public void Shuffle(int[] arr)
-
Shuffle
public void Shuffle(int[] arr, int numberOfShuffles)
-
Shuffle
public void Shuffle(double[] arr, int sampleSize, int numberOfShuffles)Shuffles an array of doubles- Parameters:
arr- array to be shuffledsampleSize- number of elements from array that shuffling can deltasnumberOfShuffles- number of elements that will be shuffled, should not exceed lenToShuffle
-
Shuffle
public void Shuffle(double[] arr, int numberOfShuffles)
-
Shuffle
public void Shuffle(double[] arr)
-
Shuffle
public void Shuffle(java.lang.Object[] arr, int sampleSize, int numberOfShuffles)Shuffles an array of objects- Parameters:
arr- array to be shuffledsampleSize- number of elements from array that shuffling can deltasnumberOfShuffles- number of elements that will be shuffled, should not exceed lenToShuffle
-
Shuffle
public void Shuffle(java.lang.Object[] arr)
-
-