MATLAB: Do I get correlated random numbers when I invoke RANDN after incrementing the seed by a small number in MATLAB 7.5 (R2007b)

MATLABrandrandnseedstate

When I execute the following code
test = zeros(1,1000);
for n=1:1000
randn('state', n);
test(n) = randn;
end
I notice that the "random" elements in the variable "test" are correlated with each other beyond what I would expect from a random sampling of the normal distribution.

Best Answer

Successively incrementing the seed for RANDN and then invoking RANDN will produce highly correlated outputs and, for this reason, is not the suggested use for RANDN. The correct way to use RANDN is to initialize the state of RANDN outside the FOR loop:
test = zeros(1,1000);
randn('state', 0);
for n=1:1000
test(n) = randn;
end
Once this is done, invoking the RANDN function inside the loop will generate uncorrelated random numbers in successive iterations. This will also create reproducible results from one execution of code to the next.