Hi,

I am very new to Julia but need it for numerical simulations for my master thesis.

I am using the Distributions package, since I have to sample from a von Mises Distribution with parameter \kappa.

Generally sampling from a von Mises distribution works, however in my code I have to do that within a function, since the parameter \kappa depends on other variables defined in the function’s scope.

Unfortunately I cannot get that to work, and I always get an “UndefVarError: Distributions not defined” error.

I assume there is some issue with the scope of variables, however I have no idea how to get the code to work.

Here is the function, where I want to sample from a von Mises distribution (var.n_label[i,j] is a boolean variable, defined in another function above this one):

```
function set_neighbour_orientation(param,var)
for i=1:param.N
tmpx = tmpy = 0.0
for j=1:param.N
tmpx += var.n_label[i,j] * cos(var.θ[j])
tmpy += var.n_label[i,j] * sin(var.θ[j])
end
avg_tmpx = tmpx/param.N
avg_tmpy = tmpy/param.N #(define the flux)
J_i =(avg_tmpx, avg_tmpy)
square = avg_tmpx * avg_tmpx + avg_tmpy * avg_tmpy
κ = sqrt(square)
vm = Distributions.VonMises(κ)
var.ψ[i] = rand(vm)
end
end
```