Skip to content

Distribution functions

Distribution functions

Functions

Name Description
bernoulli_distribution Generate a random boolean value based on the given probability.
binomial_distribution Generate a random value from a binomial distribution.
discrete_distribution Generate a random index based on a discrete probability distribution.
normal_distribution Generate a random value from a normal (Gaussian) distribution.
poisson_distribution Generate a random value from a Poisson distribution.
uniform_int_distribution Generate a random integer uniformly distributed in the range [min, * max].
uniform_real_distribution Generate a random floating-point number uniformly distributed in the range [min, max).

Function Details

bernoulli_distribution

bool bernoulli_distribution(random_engine_t *engine, double probability)

Generate a random boolean value based on the given probability.

engine
A pointer to the random engine.
probability
The probability of returning true (between 0.0 and 1.0).
Return
A random boolean value (true with the specified probability).

binomial_distribution

uint64_t binomial_distribution(random_engine_t *engine, uint64_t n, double p)

Generate a random value from a binomial distribution.

engine
A pointer to the random engine.
n
The number of trials (must be >= 0).
p
The probability of success in a single trial (range: [0.0, 1.0]).
Return
A random value representing the number of successes in the range [0, n].

discrete_distribution

size_t discrete_distribution(random_engine_t *engine, const double *weights, size_t size)

Generate a random index based on a discrete probability distribution.

engine
A pointer to the random engine.
weights
An array of probabilities for each index.
size
The number of elements in the weights array.
Return
A random index in the range [0, size-1], sampled according to the given probabilities.

normal_distribution

double normal_distribution(random_engine_t *engine, double mu, double sigma)

Generate a random value from a normal (Gaussian) distribution.

engine
A pointer to the random engine.
mu
The mean of the distribution.
sigma
The standard deviation of the distribution.
Return
A random value sampled from the normal distribution, which theoretically ranges from -∞ to +∞.

poisson_distribution

uint64_t poisson_distribution(random_engine_t *engine, double lambda)

Generate a random value from a Poisson distribution.

engine
A pointer to the random engine.
lambda
The mean of the Poisson distribution (must be > 0).
Return
A random value representing the number of events in the range [0, ∞).

uniform_int_distribution

int uniform_int_distribution(random_engine_t *engine, int min, int max)

Generate a random integer uniformly distributed in the range [min, * max].

engine
A pointer to the random engine.
min
The minimum value (inclusive).
max
The maximum value (inclusive).
Return
A random integer in the specified range.

uniform_real_distribution

double uniform_real_distribution(random_engine_t *engine, double min, double max)

Generate a random floating-point number uniformly distributed in the range [min, max).

engine
A pointer to the random engine.
min
The minimum value (inclusive).
max
The maximum value (exclusive).
Return
A random floating-point number in the specified range.