This file defines the basic pseudorandom number generation functionality used by the core library, as well as functions to sample from a number of built-in distributions such as categorical, discrete uniform, continuous uniform, Bernoulli, geometric, beta, gamma, and Dirichlet.
Returns the initial random seed used by all core functions that require pseudorandom number generation.
Sets the seed of the underlying pseudorandom number generator.
Reads the state of the pseudorandom number generator from in
. This is useful to persist the state of the pseudorandom number generator.
Writes the state of the pseudorandom number generator to out
. This is useful to persist the state of the pseudorandom number generator.
Samples from a categorical distribution, where the unnormalized probability of returning the index i
is given by probability[i]
. This function normalizes and overwrites probability
with its cumulative distribution function.
const U * | probability, | |
V | random, | |
unsigned int | length | ) |
Returns the smallest index i
such that random < sum from j=0 to i-1 of probability[j]
. Thus, this function implements the inverse cumulative distribution function for the categorical distribution with unnormalized probabilities given by probability
.
Samples from a categorical distribution, where the unnormalized probability of returning the index i
is given by probability[i]
and its sum is given by the floating-point sum
. This function doesn't modify probability
.
Samples from a categorical distribution, where the unnormalized probability of returning the index i
is given by probability[i]
and its sum is given by the unsigned integer sum
. This function doesn't modify probability
.
Returns a sample from the discrete uniform distribution over {0, ..., n - 1}
.
Returns a sample from the discrete uniform distribution over elements
.
Returns a sample from the discrete uniform distribution over elements
.
Returns a sample from the discrete uniform distribution over elements
.
Returns a sample from the continuous uniform distribution over [0, 1].
Returns a sample from the Bernoulli distribution: with probability 0.5, true
is returned, otherwise false
is returned.
Returns a sample from the geometric distribution with success probability p
.
Returns a sample from the negative binomial distribution with number of failures r
and success probability p
.
Returns a sample from the beta distribution with shape parameter alpha
and scale parameter 1. This function assumes alpha > 0
.
Returns a sample from the beta distribution with shape parameter alpha
and scale parameter beta
. This function assumes alpha > 0
and beta > 0
.
Returns a sample from the gamma distribution with shape parameter alpha
and rate parameter beta
. This function assumes alpha > 0
and beta > 0
.
Returns the log probability of drawing the observation x
from a gamma distribution with shape parameter alpha
and rate parameter beta
. This function assumes x > 0
, alpha > 0
, and beta > 0
.
Samples from the Dirichlet distribution with parameter alpha
and dimension length
. The sample is written to dst
. This function assumes dst
has size at least length
, alpha[i] > 0
for all i = 0, ..., length - 1
.