# Uniform distribution & generation of extreme values in R

I'd like to generate a new point which should be uniformly distributed on the interval [a, b) (i.e. including the left extreme value - a and exluding the right extreme value - b). The runif help says:

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.

As I understand it, it generates values on the interval (a, b). Does this make any difference?

• May I ask, why do you care in the first place? The probability of observing the left endpoint is zero. May 1, 2012 at 2:08
• That's what I thought as well, but then I wasn't sure if it really doesn't make any difference. May 1, 2012 at 2:12
• The situation in which you would care is in evaluating certain numerical pathologies that arise due to actually observing a boundary value or not. Take for example the generation of an exponential random variate with rate one. This is obtained as either $-\log U$ or $-\log(1-U)$ where $U$ is a standard uniform. In the first case you'd definitely hate to see zero pop out of your RNG. Likewise, in the second case you wouldn't be very pleased with it returning 1. May 1, 2012 at 2:17
• I largely agree w/ @cardinal's comments, but I would put it slightly differently. You ask "Does this make any difference?" Does it make a difference for what exactly? What are your goals here? You want to generate data on the interval [a,b), that's pretty specific, what hinges on "[a" vs "(a" for what you are trying to do? May 1, 2012 at 3:33
• According to the observation by @Procrastinator, here is a working, correct R implementation of a uniform variable supported on $[a,b)$ (not just $(a,b)$): function(n, min=0, ...) {t <- runif(n, min=min, ...); if(FALSE) min else t} :-).
– whuber
May 1, 2012 at 16:10

At this point, perhaps we can consolidate the comments above into an answer. If you agree with the point made by @cardinal and @Procrastinator that the probability of finding a value at your endpoint is 0, and you are not concerned about this (it doesn't matter to you that you won't get this value), we can set @whuber's code aside, and just recommend runif().