I need to generate a random sample between (0,1) and freeze it so that when I run the program again it generates the same "random" sample. Matlab help gave me:
% Save v5 generator state.
st = rand('state');% Call rand.
x = rand(1,4);% Restore v5 generator state.
rand('state',st);% Call rand again and hope
% for the same results.
y = rand(1,4)
First iteration output is: x =
0.59494 0.27395 0.0481 0.83809y = 0.59494 0.27395 0.0481 0.83809
But second run produces different sequence: x =
0.10254 0.72827 0.4405 0.99719y = 0.10254 0.72827 0.4405 0.99719
I need it to give me the same results, so the second run should be: x =
0.59494 0.27395 0.0481 0.83809 y = 0.59494 0.27395 0.0481 0.83809
I know this involves using a seed but the help wasn't clear to me. The rng function doesn't work in my version.
Best Answer