rand.dist #

Non-Uniform Distribution Functions

This module contains functions for sampling from non-uniform distributions.

All implementations of the rand.PRNG interface generate numbers from uniform distributions. This library exists to allow the generation of pseudorandom numbers sampled from non-uniform distributions. Additionally, it allows the user to use any PRNG of their choice. This is because the default RNG can be reassigned to a different generator. It can either be one of the pre-existing one (which are well-tested and recommended) or a custom user-defined one. See rand.set_rng().

fn bernoulli #

fn bernoulli(p f64) bool

bernoulli returns true with a probability p. Note that 0 <= p <= 1.

fn binomial #

fn binomial(n int, p f64) int

binomial returns the number of successful trials out of n when the probability of success for each trial is p.

fn exponential #

fn exponential(lambda f64) f64

exponential returns an exponentially distributed random number with the rate paremeter lambda. It is expected that lambda is positive.

fn normal #

fn normal(config NormalConfigStruct) f64

normal returns a normally distributed random number with the mean mu and standard deviation sigma. If not specified, mu is 0 and sigma is 1. Intended usage is x := normal(mu: mean, sigma: etdev) or x := normal(). NOTE: If you are generating a lot of normal variates, use the normal_pair function instead. This function discards one of the two variates generated by the normal_pair function.

fn normal_pair #

fn normal_pair(config NormalConfigStruct) (f64, f64)

normal_pair returns a pair of normally distributed random numbers with the mean mu and standard deviation sigma. If not specified, mu is 0 and sigma is 1. Intended usage is x, y := normal_pair(mu: mean, sigma: stdev), or x, y := normal_pair().

struct NormalConfigStruct #

struct NormalConfigStruct {
	mu    f64 = 0.0
	sigma f64 = 1.0
}

Configuration struct for the normal_pair function. The default value for mu is 0 and the default value for sigma is 1.