HSoM-1.0.0: Library for computer music education

System.Random.Distributions

Synopsis

# Random Distributions

linear :: (RandomGen g, Floating a, Random a, Ord a) => g -> (a, g) Source #

Given a random number generator, generates a linearly distributed random variable between 0 and 1. Returns the random value together with a new random number generator. The probability density function is given by

f(x) = 2(1-x)  0 <= x <= 1
= 0       otherwise

Arguments

 :: (RandomGen g, Floating a, Random a, Eq a) => a horizontal spread of the function. -> g a random number generator. -> (a, g)

Generates an exponentially distributed random variable given a spread parameter lambda. A larger spread increases the probability of generating a small number. The mean of the distribution is 1/lambda. The range of the generated number is [0,inf] although the chance of getting a very large number is very small.

The probability density function is given by

f(x) = lambda e^(-lambda * x)

Arguments

 :: (Floating a, Ord a, Random a, RandomGen g) => a horizontal spread of the function. -> g a random number generator. -> (a, g)

Generates a random number with a bilateral exponential distribution. Similar to exponential, but the mean of the distribution is 0 and 50% of the results fall between (-1lambda, 1lambda).

Arguments

 :: (Floating a, Random a, RandomGen g) => a standard deviation. -> a mean. -> g a random number generator. -> (a, g)

Generates a random number with a Gaussian distribution.

Arguments

 :: (Floating a, Random a, RandomGen g, Eq a) => a alpha (density). -> g a random number generator. -> (a, g)

Generates a Cauchy-distributed random variable. The distribution is symmetric with a mean of 0.

poisson :: (Num t, Ord a, Floating a, RandomGen g, Random a) => a -> g -> (t, g) Source #

Generates a Poisson-distributed random variable. The given parameter lambda is the mean of the distribution. If lambda is an integer, the probability that the result j=lambda-1 will be as great as that of j=lambda. The Poisson distribution is discrete. The returned value will be a non-negative integer.

frequency :: (Floating w, Ord w, Random w, RandomGen g) => [(w, a)] -> g -> (a, g) Source #

Given a list of weight-value pairs, generates a value randomly picked from the list, weighting the probability of choosing each value by the weight given.

# Utility Functions

rands :: (RandomGen g, Random a) => (g -> (a, g)) -> g -> [a] Source #

Given a function generating a random number variable and a random number generator, produces an infinite list of random values generated from the given function.