I have a rather basic question but can't figure out a foolproof answer. In the following code, I build a function which returns the mean difference between successive elements of a vector created from j
random variates from an exponential distribution:
fun2[j_] :=
Module[{x = RandomVariate[ExponentialDistribution[1/25], j]},
Mean[Table[Abs[x[[i + 1]] - x[[i]]], {i, Length[x] - 1}]]]
Will the use of the x
call to RandomVariate
create an immutable object, i.e. so that x[[i + 1]]
and x[[i]]
reference the same instance of the distribution?
Thanks a lot for any help.
Mean[Abs@Differences[x]]
? That seems a lot simpler here. Not to mention, it will be much faster. $\endgroup$