[R] unif_rand() and exp_rand()

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Mon Nov 25 08:41:27 CET 2002


I've not met this, but it is in principle possible for some of the
random-number generators (including user-supplied, of course).  It may
also depend on the arithmetic on the platform used, which may depend on
the compiler used.  So usages of unif_rand should be able to handle 0 or
1. I will alter exp_rand to do so.

On Sun, 24 Nov 2002, Paul Y. Peng wrote:

> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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