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: Rik
Subject: [Octave-bug-tracker] [bug #53299] Several rand/randn bugs with state/seed behavior.
Date: Wed, 7 Mar 2018 18:09:53 -0500 (EST)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0

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

Bug 1 is also probably explained by the first sentence where it says it is not
possible to mix the two generators.  From the normal rand documentation


Older versions of Octave used a different random number generator.
The new generator is used by default as it is significantly faster
than the old generator, and produces random numbers with a
significantly longer cycle time.  However, in some circumstances it
might be desirable to obtain the same random sequences as produced
by the old generators.  To do this the keyword "seed" is used to
specify that the old generators should be used, as in

     rand ("seed", val)

which sets the seed of the generator to VAL.  The seed of the
generator can be queried with

     s = rand ("seed")

However, it should be noted that querying the seed will not cause
'rand' to use the old generators, only setting the seed will.  To
cause 'rand' to once again use the new generators, the keyword
"state" should be used to reset the state of the 'rand'.


Examining the test code


aa = sum(rand('seed')); randn('seed', 'reset'); bb = sum(rand('seed'));
assert(aa!=bb); 


The first fragment queries the rand "seed" which does not switch generators. 
The second fragment executes a reset of the randn "seed" and also switches the
random number generators from the new to the old.  When you switch generators
entirely there is no guarantee on the behavior of the seeds.  I guess that
could be documented.  It would be nicer to simply remove the old random number
generator functionality entirely.


    _______________________________________________________

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]