The title says it all. Can it happen that runif (with bounds 0 and 1) returns 0 or 1 in R?
1 Answer
It sounds like you're already aware that drawing a 0 or 1 from the standard uniform distribution is a zero-probability event. Instead, as I understand it your question is specifically about R, and whether runif
will return 0 or 1 due to the finite numerical precision of your computer. We can read the following from ?runif
:
runif will not generate either of the extreme values unless max = min or max-min is small compared to min, and in particular not for the default arguments.
So we conclude that drawing from the standard uniform distribution in R using runif
will never return 0 or 1. You are safe to, for instance, log-transform the result without worrying about whether you will obtain finite values.
-
5$\begingroup$ Re your last sentence: most people are perfectly content with finite values; its the other kind that worry them... $\endgroup$– Glen_bCommented Mar 24, 2020 at 4:54