KSLRandom

object KSLRandom

The purpose of this class is to facilitate random variate generation from various distributions without having to create object instances.

Each function marked rXXXX will generate random variates from the named distribution. The user has the option of supplying a RNStreamIfc as the source of the randomness. Functions that do not have a RNStreamIfc parameter use, defaultRNStream() as the default source of randomness. That is, they all share the same stream, which is the default stream from the default random number stream provider. The user has the option of supplying a stream number to identify the stream from the underlying stream provider. By default, stream 1 is the default stream for the default provider. Stream 2 refers to the 2nd stream, etc.

Also provides a number of methods for sampling with and without replacement from arrays and lists as well as creating permutations of arrays and lists.

Author

rossetti

Types

Link copied to clipboard

Properties

Link copied to clipboard

The default stream number for the underlying provider

Functions

Link copied to clipboard
Link copied to clipboard

Randomly selects from the array using the supplied cdf, NO checking of arrays

Link copied to clipboard
Link copied to clipboard

Each element must be in (0,1) and sum of elements must be less than or equal to 1.0.

Link copied to clipboard

There must be at least two elements in the supplied array. All elements must be probabilities within 0.0, 1.0. The sum of the probabilities must be 1.0

Link copied to clipboard

Makes an array that holds the probability mass function associated with the supplied discrete cumulative distribution function.

Link copied to clipboard
Link copied to clipboard
fun <T> permute(x: Array<T>, streamNum: Int)
fun permute(x: DoubleArray, streamNum: Int)
fun permute(x: DoubleArray, stream: RNStreamIfc = defaultRNStream())

Randomly permutes the supplied array using the supplied stream number, the array is changed

fun <T> permute(x: Array<T>, rng: RNStreamIfc = defaultRNStream())

Randomly permutes the supplied array using the supplied random number generator, the array is changed

fun permute(x: BooleanArray, streamNum: Int)
fun permute(x: IntArray, streamNum: Int)

Randomly permutes the supplied array using the supplied stream number, the array is changed.

fun permute(x: BooleanArray, rng: RNStreamIfc = defaultRNStream())
fun permute(x: IntArray, rng: RNStreamIfc = defaultRNStream())

Randomly permutes the supplied array using the supplied random number generator, the array is changed.

fun <T> permute(x: MutableList<T>, streamNum: Int)

Randomly permutes the supplied List using the supplied stream number, the list is changed

fun <T> permute(x: MutableList<T>, stream: RNStreamIfc = defaultRNStream())

Randomly permutes the supplied List using the supplied random number generator, the list is changed

Link copied to clipboard
fun randomlySelect(array: DoubleArray, streamNum: Int): Double
fun randomlySelect(array: DoubleArray, stream: RNStreamIfc = defaultRNStream()): Double
fun randomlySelect(array: IntArray, streamNum: Int): Int
fun randomlySelect(array: IntArray, stream: RNStreamIfc = defaultRNStream()): Int

Randomly select an element from the array

fun <T> randomlySelect(list: List<T>, streamNum: Int): T
fun <T> randomlySelect(list: List<T>, stream: RNStreamIfc = defaultRNStream()): T

Randomly select from the list

fun randomlySelect(array: DoubleArray, cdf: DoubleArray, streamNum: Int): Double
fun randomlySelect(array: DoubleArray, cdf: DoubleArray, stream: RNStreamIfc = defaultRNStream()): Double
fun randomlySelect(array: IntArray, cdf: DoubleArray, streamNum: Int): Int
fun randomlySelect(array: IntArray, cdf: DoubleArray, stream: RNStreamIfc = defaultRNStream()): Int

Randomly selects from the array using the supplied cdf

fun <T> randomlySelect(list: List<T>, cdf: DoubleArray, streamNum: Int): T
fun <T> randomlySelect(list: List<T>, cdf: DoubleArray, stream: RNStreamIfc = defaultRNStream()): T

Randomly selects from the list using the supplied cdf

Link copied to clipboard
fun rBernoulli(pSuccess: Double, streamNum: Int): Double
fun rBernoulli(pSuccess: Double, stream: RNStreamIfc = defaultRNStream()): Double
Link copied to clipboard
fun rBernoulliBoolean(pSuccess: Double, stream: RNStreamIfc = defaultRNStream()): Boolean
Link copied to clipboard
fun rBeta(alpha: Double, beta: Double, streamNum: Int): Double
fun rBeta(alpha: Double, beta: Double, rng: RNStreamIfc = defaultRNStream()): Double

This beta is restricted to the range of (0,1)

Link copied to clipboard
fun rBetaG(alpha: Double, beta: Double, minimum: Double, maximum: Double, streamNum: Int): Double
fun rBetaG(alpha: Double, beta: Double, minimum: Double, maximum: Double, rng: RNStreamIfc = defaultRNStream()): Double

This beta is restricted to the range of (minimum,maximum)

Link copied to clipboard
fun rBinomial(pSuccess: Double, nTrials: Int, streamNum: Int): Int
fun rBinomial(pSuccess: Double, nTrials: Int, stream: RNStreamIfc = defaultRNStream()): Int
Link copied to clipboard
fun rChiSquared(dof: Double, streamNum: Int): Double
fun rChiSquared(dof: Double, rng: RNStreamIfc = defaultRNStream()): Double
Link copied to clipboard
fun rDUniform(range: IntRange, streamNum: Int): Int
fun rDUniform(range: IntRange, stream: RNStreamIfc = defaultRNStream()): Int
fun rDUniform(minimum: Int, maximum: Int, streamNum: Int): Int
fun rDUniform(minimum: Int, maximum: Int, stream: RNStreamIfc = defaultRNStream()): Int

Generates a discrete uniform over the range

Link copied to clipboard
fun rExponential(mean: Double, streamNum: Int): Double
fun rExponential(mean: Double, stream: RNStreamIfc = defaultRNStream()): Double
Link copied to clipboard
fun rGamma(shape: Double, scale: Double, streamNum: Int, type: KSLRandom.AlgoType = AlgoType.Inverse): Double
fun rGamma(shape: Double, scale: Double, rng: RNStreamIfc = defaultRNStream(), type: KSLRandom.AlgoType = AlgoType.Inverse): Double
Link copied to clipboard
fun rGeometric(pSuccess: Double, streamNum: Int): Int
fun rGeometric(pSuccess: Double, stream: RNStreamIfc = defaultRNStream()): Int
Link copied to clipboard
fun rJohnsonB(alpha1: Double, alpha2: Double, min: Double, max: Double, streamNum: Int): Double
fun rJohnsonB(alpha1: Double, alpha2: Double, min: Double, max: Double, stream: RNStreamIfc = defaultRNStream()): Double
Link copied to clipboard
fun rLaplace(location: Double, scale: Double, streamNum: Int): Double
fun rLaplace(location: Double, scale: Double, rng: RNStreamIfc = defaultRNStream()): Double

Generates according to a Laplace(location, scale)

Link copied to clipboard
fun rLogistic(location: Double, scale: Double, streamNum: Int): Double
fun rLogistic(location: Double, scale: Double, rng: RNStreamIfc = defaultRNStream()): Double
Link copied to clipboard
fun rLogLogistic(shape: Double, scale: Double, streamNum: Int): Double
fun rLogLogistic(shape: Double, scale: Double, rng: RNStreamIfc = defaultRNStream()): Double
Link copied to clipboard
fun rLogNormal(mean: Double, variance: Double, streamNum: Int): Double
fun rLogNormal(mean: Double, variance: Double, stream: RNStreamIfc = defaultRNStream()): Double
Link copied to clipboard
fun rNegBinomial(pSuccess: Double, rSuccesses: Double, streamNum: Int): Int
fun rNegBinomial(pSuccess: Double, rSuccesses: Double, stream: RNStreamIfc = defaultRNStream()): Int
Link copied to clipboard
fun rNormal(streamNum: Int): Double

Generates a N(0,1) random value using the supplied stream number

fun rNormal(stream: RNStreamIfc): Double

Generates a N(0,1) random value using the supplied stream

fun rNormal(mean: Double, variance: Double, streamNum: Int): Double
fun rNormal(mean: Double = 0.0, variance: Double = 1.0, stream: RNStreamIfc = defaultRNStream()): Double
Link copied to clipboard
fun rNormalBoxMuller(mean: Double = 0.0, variance: Double = 1.0, streamNum: Int): Pair<Double, Double>
fun rNormalBoxMuller(mean: Double = 0.0, variance: Double = 1.0, stream: RNStreamIfc = defaultRNStream()): Pair<Double, Double>

Generated a pair of normal random variates via the Box-Muller transform method The user can use destructuring to access the individual values

Link copied to clipboard
fun rNormalPolar(mean: Double = 0.0, variance: Double = 1.0, streamNum: Int): Pair<Double, Double>
fun rNormalPolar(mean: Double = 0.0, variance: Double = 1.0, stream: RNStreamIfc = defaultRNStream()): Pair<Double, Double>

Generated a pair of normal random variates via the Box-Muller transform method The user can use destructuring to access the individual values

Link copied to clipboard
fun rnStream(streamNum: Int): RNStreamIfc
Link copied to clipboard
fun rPearsonType5(shape: Double, scale: Double, streamNum: Int): Double
fun rPearsonType5(shape: Double, scale: Double, rng: RNStreamIfc = defaultRNStream()): Double
Link copied to clipboard
fun rPearsonType6(alpha1: Double, alpha2: Double, beta: Double, streamNum: Int): Double
fun rPearsonType6(alpha1: Double, alpha2: Double, beta: Double, rng: RNStreamIfc = defaultRNStream()): Double

Pearson Type 6

Link copied to clipboard
fun rPoisson(mean: Double, streamNum: Int): Int
fun rPoisson(mean: Double, stream: RNStreamIfc = defaultRNStream()): Int
Link copied to clipboard
fun rTriangular(min: Double, mode: Double, max: Double, streamNum: Int): Double
fun rTriangular(min: Double, mode: Double, max: Double, stream: RNStreamIfc = defaultRNStream()): Double
Link copied to clipboard
fun rUniform(streamNum: Int): Double

Generates a continuous U(0,1) using the supplied stream number

fun rUniform(stream: RNStreamIfc = defaultRNStream()): Double

Generates a continuous U(0,1) using the supplied stream

fun rUniform(minimum: Double, maximum: Double, streamNum: Int): Double
fun rUniform(minimum: Double = 0.0, maximum: Double = 1.0, stream: RNStreamIfc = defaultRNStream()): Double

Generates a continuous uniform over the range

Link copied to clipboard
fun rWeibull(shape: Double, scale: Double, streamNum: Int): Double
fun rWeibull(shape: Double, scale: Double, stream: RNStreamIfc = defaultRNStream()): Double
Link copied to clipboard
fun <T> sampleWithoutReplacement(x: Array<T>, sampleSize: Int, streamNum: Int)
fun <T> sampleWithoutReplacement(x: Array<T>, sampleSize: Int, stream: RNStreamIfc = defaultRNStream())

The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x0, x1, ... , xsampleSize-1 is the randomly sampled values without replacement

fun sampleWithoutReplacement(x: BooleanArray, sampleSize: Int, streamNum: Int)
fun sampleWithoutReplacement(x: BooleanArray, sampleSize: Int, rng: RNStreamIfc = defaultRNStream())
fun sampleWithoutReplacement(x: IntArray, sampleSize: Int, streamNum: Int)
fun sampleWithoutReplacement(x: IntArray, sampleSize: Int, rng: RNStreamIfc = defaultRNStream())

The array x is changed, such that the first sampleSize elements contain the generated sample. That is, x0, x1, ... , xsampleSize-1 is the random sample without replacement

fun sampleWithoutReplacement(x: DoubleArray, sampleSize: Int, streamNum: Int)
fun sampleWithoutReplacement(x: DoubleArray, sampleSize: Int, rng: RNStreamIfc = defaultRNStream())

The array x is changed, such that the first sampleSize elements contain the sample. That is, x0, x1, ... , xsampleSize-1 is the random sample without replacement

fun <T> sampleWithoutReplacement(x: MutableList<T>, sampleSize: Int, streamNum: Int)

The List x is changed, such that the first sampleSize elements contain the generate. That is, x.get(0), x.get(1), ... , x.get(sampleSize-1) is the random sample without replacement

fun <T> sampleWithoutReplacement(x: MutableList<T>, sampleSize: Int, stream: RNStreamIfc = defaultRNStream())

The List x is changed, such that the first sampleSize elements contain the sampled values. That is, x.get(0), x.get(1), ... , x.get(sampleSize-1) is the random sample without replacement

Link copied to clipboard