Re: Length of cycle for random numbers



Joseph K. wrote:
On Fri, 20 Jul 2007 16:30:21 -0600, "Jim Hewitt"
<jim.hewitt@xxxxxxxxxxxxxxx> wrote:

"Joseph K." <nihil@xxxxxxxx> wrote in message news:1jc2a31vm6kt9ieubifnv0c0nr30b0o1o5@xxxxxxxxxx
Hi Matlab experts:
I've carried out intensive calculations using randn in many parts of
my code and I have noticed that in some replicate runs exactly the
same resuls have been produced. I think I've reached some sort of
limit cycle in the random number generator. How can I avoid this
behavior? Do I need to set randn to some unique state in the very
first few lines every time I run again my program?
TIA
Joseph K.
"Random" numbers in computers are pseudo-random, which includes repeating he sequence though it is usually are large enough count before it repeats. Given the same seed, the generator will produce htesame sequence. The solution is to reset the seed every now and then using something quasi-random.

randn('state',sum(100*clock)) Resets it to a different state each time.

Jim

Thanks Jim.
I thought that Matlab by default reset the seed using the clock every
time the random number generator (rng) was called.
Is this another option?:
randn('state',j)
where 'j' is entered by the user when the program starts and it asks
to write 'a large integer typed haphazardly'.
I'm not sure because 'j' may necessarily be a previous state of the
rng rather than any integer.


It is a good idea to have the option of setting the seed yourself, because it means you can replicate a run if necessary. You could code it so that when the user enters a seed of zero (for example) the seed is generated from the time. Note that, as someone else mentioned, the seed should be specified just once, at the start of the run - this defines a unique pseudo-random sequence.
.



Relevant Pages

  • Re: Length of cycle for random numbers
    ... I've carried out intensive calculations using randn in many parts of ... Do I need to set randn to some unique state in the very ... the generator will produce htesame sequence. ... because it means you can replicate a run if necessary. ...
    (comp.soft-sys.matlab)
  • Re: Length of cycle for random numbers
    ... I've carried out intensive calculations using randn in many parts of ... Do I need to set randn to some unique state in the very ... the generator will produce htesame sequence. ...
    (comp.soft-sys.matlab)
  • Re: Length of cycle for random numbers
    ... Do I need to set randn to some unique state in the very ... the generator will produce htesame sequence. ... I thought that Matlab by default reset the seed using the clock every ... time the random number generator (rng) was called. ...
    (comp.soft-sys.matlab)
  • Re: gamma random function
    ... for either rand or else randn just prior to generating the sequence of gammarnd quantities to make them repeat the same sequence of values. ... Of course that presupposes that other differing uses of rand or randn do not intervene during such a generation sequence. ... And gamrnd calls randg, so this also apply to gamrnd. ...
    (comp.soft-sys.matlab)
  • Re: Length of cycle for random numbers
    ... Do I need to set randn to some unique state in the very ... "Random" numbers in computers are pseudo-random, which includes repeating he ... the generator will produce htesame sequence. ... solution is to reset the seed every now and then using something ...
    (comp.soft-sys.matlab)