View Source CEM.Random (cem v0.1.0)

Convenience functions for generating random variates.

Summary

Functions

Generate a bernoulli variate (0 or 1) with probability p of being 1.

Generate a random value from a list of {value, weight} tuples.

Generate a normal variate with mean mean and standard deviation std.

Generate a uniform variate from 0 to 1.

Generate a uniform variate from min_value to max_value.

Generate a random integer from min_value to max_value (inclusive).

Functions

@spec bernoulli(number()) :: 0 | 1

Generate a bernoulli variate (0 or 1) with probability p of being 1.

@spec choice([{any(), number()}]) :: any()

Generate a random value from a list of {value, weight} tuples.

The probability of selecting a value is proportional to its weight. The weights do not need to be normalized.

An exception is raised if the list is empty.

@spec normal(number(), number()) :: float()

Generate a normal variate with mean mean and standard deviation std.

@spec uniform() :: float()

Generate a uniform variate from 0 to 1.

Link to this function

uniform(min_value, max_value)

View Source
@spec uniform(number(), number()) :: float()

Generate a uniform variate from min_value to max_value.

Link to this function

uniform_int(min_value, max_value)

View Source

Generate a random integer from min_value to max_value (inclusive).