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.Serializable
contains functions for random value generation and distribution sampling.
Serialized Form
• Constructor Summary

Constructors
Constructor Description
Rand()
Rand​(long seed)
Rand​(RNG rng)
creates a Rand object using the RNG argument as its internal generator
• Method Summary

Modifier and Type Method Description
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)
long Binomial​(long n, double p)
returns a random number from the binomial distribution
boolean Bool()
returns a random boolean value (true or false)
double Double()
returns a random double from 0 to 1
double Double​(double bound)
returns a random double from 0 up to bound
double Double​(int bound)
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
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)
int Int​(int bound)
returns a random integer from 0 up to (not including) bound
long Long​(long bound)
returns a random long from 0 up to (not including) bound
void Multinomial​(double[] probabilities, int n, int[] ret)
void Multinomial​(double[] probabilities, long n, long[] ret)
void RandomDS​(double[] out, double min, double max)
Fills out with random doubles between min and max inclusive
void RandomIS​(int[] out, int min, int max)
Fills out with random integers between min (inclusive) and max (exclusive)
gets a random point on the surface of a circle centered at 0,0, with the provided radius.
gets a random point on the surface of a sphere centered at 0,0,0, with the provided radius.
int RandomVariable​(double[] probs)
Samples a discrete random variable from the probabilities provided
int RandomVariable​(double[] probs, double rand, int start, int end)
int RandomVariable​(double[] probs, int start, int end)
void Shuffle​(double[] arr)
void Shuffle​(double[] arr, int numberOfShuffles)
void Shuffle​(double[] arr, int sampleSize, int numberOfShuffles)
Shuffles an array of doubles
void Shuffle​(int[] arr)
void Shuffle​(int[] arr, int numberOfShuffles)
void Shuffle​(int[] arr, int sampleSize, int numberOfShuffles)
Shuffles an array of integers
void Shuffle​(java.lang.Object[] arr)
void Shuffle​(java.lang.Object[] arr, int sampleSize, int numberOfShuffles)
Shuffles an array of objects
• Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• Field Detail

• rn

public final RNG rn
• gn

public final Gaussian gn
• bn

public final Binomial bn
• 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

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

double[] ret)
• RandomPointOnCircleEdge

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

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 shuffled
sampleSize - number of elements from array that shuffling can deltas
numberOfShuffles - 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 shuffled
sampleSize - number of elements from array that shuffling can deltas
numberOfShuffles - 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 shuffled
sampleSize - number of elements from array that shuffling can deltas
numberOfShuffles - number of elements that will be shuffled, should not exceed lenToShuffle
• Shuffle

public void Shuffle​(java.lang.Object[] arr)