From maechler@stat.math.ethz.ch  Fri Sep 15 19:44:20 2000
From: maechler@stat.math.ethz.ch (maechler@stat.math.ethz.ch)
Date: Fri, 15 Sep 2000 20:44:20 +0200 (MET DST)
Subject: [Rd] .Random.seed resetting (PR#656)
Message-ID: <200009151844.UAA19859@pubhealth.ku.dk>

>>>>> "MM" == Martin Maechler <maechler@stat.math.ethz.ch> writes:

>>>>> "lej25" == lej25  <lej25@statslab.cam.ac.uk> writes:
    lej25> Full_Name: Lara Jamieson Version: 1.1.1 OS: Linux Submission
    lej25> from: (NULL) (131.111.20.203)

    lej25> I've checked for other reports on this and can't find anything.
    lej25> It seems that the .Random.seed isn't updated properly after
    lej25> using rm(.Random.seed).  Mu understanding from the help file
    lej25> indicates that a new 'random' seed will be generated.  It
    lej25> appears that sometimes the old one is just reinstated.

    lej25> I removed my .RData file and the problem remains.  It seems to
    lej25> happen when calls are made in succession to the same 'random
    lej25> generation type' function; but appears to

    lej25> work when different calls are made in succession.  An example is
    lej25> given below.  I was using the sample command when I found the
    lej25> problem but it happens with runif as well...

    >>> runif(1)
    lej25> [1] 0.5551602
    >>> runif(1)
    lej25> [1] 0.2575637
    >>> rm(.Random.seed) runif(1)
    lej25> [1] 0.5551602
    >>> rm(.Random.seed) rm(.Random.seed)
    lej25> Warning message: remove: variable ".Random.seed" was not found
    >>> runif(1)
    lej25> [1] 0.2575637


    MM> [I don't get your behavior] Could it be that you have a
    MM> .Random.seed further up in your search() path?  This would explain
    MM> everything.

Well I *could* reproduce the bogous behavior in R 1.1.1, after all.

The problem is that .Random.seed is not only in .GlobalEnv, but also 
"Autoloads" :

R --vanilla

  > runif(1)
  [1] 0.4659391
  > find(".Random.seed")
  [1] ".GlobalEnv" "Autoloads" 
  > all.equal(.Random.seed, get(".Random.seed", envir = .AutoloadEnv))
  [1] TRUE

and hence, after rm(.Random.seed), runif(*) still gets the one from the
autoloads... 

This bug has just been fixed in R-devel
(by an expert, not me!), together with the even more peculiar

    > library(stepfun)
    > AbC <<- "Z"
    > find("AbC")
    [1] ".GlobalEnv"      "package:stepfun" "Autoloads"      

 {but you were told never to use "<<-"  ;-) }
     
--
Martin

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] .Random.seed resetting (PR#656)
maechler@stat.math.ethz.ch