[R] Drawing random numbers from Uniform distribution with infinite range

Ben Bolker bbo|ker @end|ng |rom gm@||@com
Mon Jul 28 19:39:35 CEST 2025


   And, this is why I keep asking for more context about what you are 
ultimately trying to accomplish. It might be that you're truly trying to 
do something that is mathematically impossible (in which case you're out 
of luck), but it could also be that we could suggest something that 
would solve your ultimate goal.

   (Someone mathier would also say that any random variable has to be 
defined with respect to a *measure*, so selecting values without respect 
to a probability distribution is also impossible ... in a different way 
from sampling uniformly from values on the real line ...)

   Ben Bolker


On 2025-07-28 1:23 p.m., Duncan Murdoch wrote:
> As others have told you, you can't.  You can talk about a uniform 
> distribution on the reals but there's no way to normlize it so it 
> integrates to 1, so it's an "improper" distribution, and there is no way 
> to sample from those.
> 
> Duncan Murdoch
> 
> On 2025-07-28 12:30 p.m., Daniel Lobo wrote:
>> Many thanks for your guidance. However my original problem is, how to
>> select n points in the Real line randomly without any preference of
>> any particular probability distribution?
>>
>> On Mon, 28 Jul 2025 at 21:45, Rui Barradas <ruipbarradas using sapo.pt> wrote:
>>>
>>> On 7/28/2025 5:00 PM, Daniel Lobo wrote:
>>>> Hi,
>>>>
>>>> I want to draw a set of random number from Uniform distribution where
>>>> Support is the entire Real line.
>>>>
>>>> runif(4, min = -Inf, max = Inf)
>>>>
>>>> However it produces all NAN
>>>>
>>>> Could you please help with the right approach?
>>>>
>>>> ______________________________________________
>>>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide https://www.R-project.org/posting- 
>>>> guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>> Hello,
>>>
>>>
>>> What you are asking doesn't make sense.
>>> The uniform distribution's PDF is
>>>
>>> f(x;a, b) = 1/abs(b - a) if x in [a, b]
>>>               0            otherwise
>>>
>>> So what you have is 1/abs(Inf - -Inf) = 1/abs(Inf) = 0.
>>>
>>> And the cumulative distribution function is even worse, it will give you
>>> the indeterminate Inf/Inf.
>>> See the Wikipedia on the uniform distribution [1].
>>>
>>>
>>> [1] https://en.wikipedia.org/wiki/Continuous_uniform_distribution
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide https://www.R-project.org/posting- 
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide https://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering
 > E-mail is sent at my convenience; I don't expect replies outside of 
working hours.



More information about the R-help mailing list