The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: randn repeating itself
Replies: 3   Last Post: Mar 29, 2013 5:36 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Peter Perkins

Posts: 156
Registered: 8/12/11
Re: randn repeating itself
Posted: Mar 28, 2013 10:44 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.