# Using SeedRandom

I have the following function definition:

P[t_] :=
P[t] =  P[t - 1] + μ*ED[t - 1] + RandomVariate[NormalDistribution[0, 0.03]];


I want to evaluate P 6000 times and I want to get the same 6000 iterations of the random variable. So I basically know how to get the same 6000 iterations, but I don't know how to create a list so I can use these values in my equation.

I tried it in a simpler way with

a = SeedRandom[5];
Table[RandomVariate[NormalDistribution[0, 0.03]], {3}];
b = {1, 2, 3};
a + b


And the output was

{1 + Null, 2 + Null, 3 + Null}


So how can I sum up the numbers resulting from SeedRandom with other numbers?

• You never assign your Table to a variable name in your "simpler" way. Jan 11, 2018 at 19:14
• Probably a =  should be in the row following SeedRandom. SeedRandom returns Null as it merely sets the seed for pseudorandom number generation. Jan 11, 2018 at 19:33
• You don't have an equation; you have a memoized definition of a recursive function. Jan 11, 2018 at 19:37
• note for your simpler case (probably what you really want) you don't even need Table since RandomVariate takes a n argument to generate a list. Jan 11, 2018 at 21:30

Since you are memoizing the values of P[i], you don't need to use SeedRandom at all. Consider,

P[0] = 1;
P[t_] := P[t] = P[t - 1] + RandomVariate[NormalDistribution[0, 0.03]]

Do[P[t], {t, 5}]
Table[P[t], {t, 5}]


{1.0187, 0.982789, 0.974296, 0.9285, 0.931482}

The call to Table didn't run the function P; it just retrieved the memoized values. Repeating the call

Table[P[t], {t, 5}]


{1.0187, 0.982789, 0.974296, 0.9285, 0.931482}

gives the same result.

• you need SeedRandom if you want the same sequence again after a kernel restart though. Jan 11, 2018 at 21:27

in direct form your recursive function looks like this I think:

  p = P[0] + u Accumulate[Table[ED[i], {i, 0, n - 1}]] +
Accumulate[RandomVariate[NormalDistribution[0, 0.03], n]]