This is a quick note on how to generate random variables in Julia and sample from them.

We first needs to load the package Distributions. If it is not already installed, you can do so with:

Pkg.add("Distributions")

using Distributions

All standard distributions are implemented and well documented. I will create a normally distributed random variable with mean 5 and standard deviation 10.

`nd = Normal(5, 10)`

We apply various functions, e.g. to get the probability density function (pdf)

`pdf(nd, 1:5)`

cdf(nd, 5)

Finally we would like to take a random sample of size 10

`rand(nd, 10)`

or fill an Array, a, with a random sample from this distribution

`a = Array(Float64, 10^5, 2);`

rand!(nd, a);

.

Advertisements