Suggested solution
If I understood the question right, then the simplest solution here would probably be to define a helper function like the following:
vv[n_] := Internal`InheritedBlock[{v}, v /@ Range[n]];
Then, you get
vel = vv[m]
and every run of vv
would result in different set of values, while the values in the set will all come from the same memoization "run".
The presence of Internal`InheritedBlock
guarantees that whatever values were remembered inside of it, will be cleared automatically when the execution leaves the block.
Example
For example:
ClearAll[f, v, s, vv];
s = 1;
f[x_] := x;
v[0] := 0;
v[n_] := v[n] = v[n - 1] + f[n - 1] + Random[NormalDistribution[0, s]];
vv[n_] := Internal`InheritedBlock[{v}, v /@ Range[n]];
Test:
vv[10]
(* {-0.0712327, 1.67558, 4.93819, 9.21973, 13.7199, 17.3607, 22.7843, 31.0941, 37.9027, 47.6244} *)
vv[10]
(* {-3.29625, -2.51668, -0.464889, 1.71271, 4.70297, 9.78192, 15.8081, 22.5965, 29.3856, 38.323} *)
Links
Closely related questions:
DownValues
. $\endgroup$Scan[Composition[Unset, v], {2, 3, 7, 8}]
. You can useRange[n]
as the list of values to clear, thus leavingv[0]
and the general rule. $\endgroup$