Martin Maechler
1998-Dec-01 08:05 UTC
Random Number Generators, .Random.seed and all that..
As some of you know, we have been thinking of allowing the possibility of a CHOICE of the kind of random number generator (=: RNG) to use in R. The current R-release snapshot even has some code in it; however, this will be changed quite a bit. Here is a kind of informal RFC (request for comments / request for criticism / ..): 1a. With the new scheme, we still want that save(..) & load(..) restore the state of the RNG. The new state is [ RNGkind ; "seed" of that RNG ]. "seed" really means the state of the chosen RNG 1b. For compatibility reasons, it makes sense to keep this RNGstate in the integer vector .Random.seed. Before each RN generation, .Random.seed is read into the internal RNG state variables; afterwards .Random.seed is restored from there. 1c. In the future, .Random.seed[1] == <code of RNGkind> .Random.seed[2:ns] == "seed" itself. ===> INCOMPATIBILITY to currently saved or set .Random.seeds. We could fudge backward compatibility by if(length(.Random.seed) == "desired length for RNGkind" - 1) { behave as if .Random.seed[0] == <current RNGkind code> .Random.seed[1:n] == <corrected .Random.seed>[2:(n+1)] } Should I provide this hack? If I don't people will more quickly have to change their code, setting proper .Random.seed whereever they assign one. 1d. Each RNG has it's own "seed" (state vector). Randomize() is only called when .Random.seed isn't there, or (new) if( length(.Random.seed) == 1 && .Random.seed[1] == "valid RNGkind code" ) 2. Default RNGkind == as now, "Wichmann-Hill" 3. In addition to .Random.seed, the RNGkind can be queried and set by RNGkind() or, e.g., RNGkind("Super-Duper") {{ my current code now provides all the above, with the exception of the full backward compatibility hack}} Comments (incl. praises :-}) welcome! Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum SOL G1; Sonneggstr.33 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1086 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._