Date: Mar 28, 2013 10:44 PM
Author: Peter Perkins
Subject: Re: randn repeating itself

On 2013/03/28 1:17, Nicholas wrote:
> This seems like a seeding problem to me, but as far as I can tell randn
> is used properly within this context. Though the way its functioning
> seems that the seed is set back to 'default' with each iteration.
> I also tried using "rng shuffle", but matlab throws an error because the
> random number is initialized with the legacy generator. Any advice?

That error from the rng function indicates that something in the code
that you have not shown us is doing something along the lines of




or something similar. This is bad on several levels, the most obvious of
which is that it's causing your image noise to be entirely predictable.
You should find the line of code and remove it.

> The problem is that the noise is the exact same with each iteration.
> BUT the perplexing thing is that if I use a breakpoint inside the loop
> and 'continue' through it, the noise changes with each iteration
> (unlike if I were to just let it run).

That seems hard to imagine, but perhaps you could add the line

rng % no semicolon

at the very beginning of your loop to try to diagnose what's going
wrong. Before you run the loop, type "rng default". Then see when the
legacy generator is being activated.