octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #53299] Several rand/randn bugs with state/see


From: Mike Miller
Subject: [Octave-bug-tracker] [bug #53299] Several rand/randn bugs with state/seed behavior.
Date: Wed, 7 Mar 2018 19:03:34 -0500 (EST)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0

Follow-up Comment #9, bug #53299 (project octave):

@rik - I'll file that as a new bug.

@deego - I do see some inconsistency with respect to your "bug 1".

TL;DR - I think rand('seed', 'reset') depends on the current time stamp. So
your test of resetting one generator and comparing the seed of the other
probably depends on round-off error with the current system clock. I haven't
looked into why, but this is probably a Matlab compatibility thing with the
old generator.

First, I have verified that randn('seed', 'reset') does switch the rand
generator to the old algorithm. But your observation that one generator resets
the other but not the other way around isn't quite correct. It seems to differ
with each run.


>> aa = rand ('seed'); randn ('seed', 'reset'); bb = rand ('seed');
>> isequal (aa, bb)
ans = 0      ## But sometimes this returns true, try it multiple times
>> aa = randn ('seed'); rand ('seed', 'reset'); bb = randn ('seed');
>> isequal (aa, bb)
ans = 0      ## But sometimes this returns true, try it multiple times


Now let's test it in loops with different timings:


>> function r = t () aa = rand ('seed'); randn ('seed', 'reset'); bb = rand
('seed'); r = isequal (aa, bb); endfunction
>> sum = 0; for i = 1:1000; sum += t (); endfor; sum
sum =  999      ## That's bad!
>> sum = 0; for i = 1:20; pause (1.1); sum += t (); endfor; sum
sum = 0


So I think this "bug 1" only occurs when the previous rand('seed', 'reset')
was done within the same second as the next one.

I don't think this is documented anywhere, but again, this would be great to
eliminate by phasing out the "old" algorithm completely.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?53299>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]