[R] unif_rand() and exp_rand()

Paul Y. Peng ypeng at math.mun.ca
Sun Nov 24 22:17:36 CET 2002


Dear R-users:

Recently I found my simulation run into an apparently infinite loop.
After a few days of tracing and chasing, I believe it is caused by
the built-in unif_rand() and exp_rand() functions: unif_rand() can
produce a value of 0 which causes the following part of exp_rand()
running into an infinity loop

    u = unif_rand();
    for (;;) {
    u += u;
    if (u > 1.0)
        break;
    a += q[0];
    }

The way I use R is slightly non-standard: I run the program in
R 1.3.1 for Linux, and my program contains the C code of
exp_rand() I grabbed from R 1.5.1 source. I am not sure whether
the problem is caused by the mixed versions of unif_rand() and
exp_rand(). If they are all the same in the two versions, then
exp_rand() always has potential to run into an infinite loop if
unif_rand() is allowed to have zero values. Does anybody
encounter similar problem?

Paul.
-- 
What one believes to be true either is true or becomes true.
                -- John Lilly
o-----------------------------------------------------------------o
  Paul Y. Peng, PhD                   Web: www.math.mun.ca/~ypeng
  Department of Mathematics and Statistics    Fax: (709) 737 3010
  Memorial University of Newfoundland       Phone: (709) 737 8080
  St. John's, NL A1C 5S7, Canada        E-mail: ypeng at math.mun.ca
o-----------------------------------------------------------------o
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list