Set (=)
stores the value at the time of computation, while SetDelayed (:=)
stores the definition, so that the value is computed again each time it is called. Therefore, writing
M = RandomVariate[NormalDistribution[0, 1]]
means using the same value over and over, while writing
M := RandomVariate[NormalDistribution[0, 1]]
means computing a new RandomVariate
at each iteration.
Moreover, no matter what your choice is about M
, while we're at it, you might want to do memoization for the whole process, i.e. write
ϕ[0] = π/4
ϕ[n_] := ϕ[n] = Exp[-n] ϕ[n - 1] + Sqrt[1 - Exp[-2 n]] M
This way when computing ϕ[n]
you store the value in your memory, so that when computing ϕ[n + 1]
you only have to recall it, instead of computing it from scratch. It is usually worth it to trade memory for speed this way.
M:=...
if you need a new one at each recursion. $\endgroup$