Daniel Lobo
2025-Jul-28 16:30 UTC
[R] Drawing random numbers from Uniform distribution with infinite range
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 at 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 at 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
Duncan Murdoch
2025-Jul-28 17:23 UTC
[R] Drawing random numbers from Uniform distribution with infinite range
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 at 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 at 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 at 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.
Chris Ryan
2025-Jul-28 17:39 UTC
[R] Drawing random numbers from Uniform distribution with infinite range
Why? What do you plan to do with those numbers? I think that was Ben's point: perhaps there is a different approach to accomplishing what you want to accomplish. What do you want to accomplish? --Chris Ryan 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 at 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? >>> >
Rui Barradas
2025-Jul-28 18:01 UTC
[R] Drawing random numbers from Uniform distribution with infinite range
On 7/28/2025 5:30 PM, 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 at 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 at 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_distributionHello, Here is another explanation on the reason why you should sample from finite limits that make sense [1]. Ben's answer points you in an acceptable direction. Here is the same idea with other limits meant to get better floating-point accuracy. n <- 1e6 # change this at will mm <- .Machine$double.xmax u <- runif(n, min = -mm/3, max = mm/3) hist(u) [1] https://math.stackexchange.com/questions/3784691/probability-distribution-of-choosing-a-real-number-at-random Hope this helps, Rui Barradas
@vi@e@gross m@iii@g oii gm@ii@com
2025-Jul-28 21:00 UTC
[R] Drawing random numbers from Uniform distribution with infinite range
If you think a bit, the requirement is silly. In computers, "real numbers" are not a real thing. They are approximations with limits in several ways, and some of these limits cannot be surmounted except perhaps someday with quantum computers which may extend the range but are not likely to totally do what you ask. Pick a bizarrely large number such as a googolplex ( ten raised to the googol power) and ask what a typical number chosen between 0 and this selected number is? A typical number, say an integer, is not likely to be in the miniscule range of 0 to the amount an integer on your machine holds. Even if you use python-style extended integers, which are not a normal part of R, the number of digits in such a random number may exceed the memory available on your machine, or even the combined machines on our planet. Picking a small enough number of something like -1,000,000,000 to 1,000,000, 000 has a probably approaching zero. Even using floating point in something like 64 bits is rapidly overwhelmed. Now, substitute a limit of infinity and negative infinity into the problem. In a mathematical sense, the average number chosen between say zero and infinity would be the nonsensical value of ?/2 which is also ?. Picking N values between -? and +? does not seem helpful for almost any purpose. The results cannot be graphed for example. And, picking a random number between zero and one can be magnified only up to a point as the number of valid digits is limited. And, as many have pointed out, when you leave the Platonic Mathematical universe and descend to using ANY computer language, such as R, the only valid large value that the machine can handle is ? itself, not as a measured amount, but as a concept. Would your need be met by simply choosing large numbers for the range that do not propagate infinities in the software but are representative enough? As noted by others, you at least may need to stay under half the largest number a machine allows unless you use a package supporting indefinite precision numbers. But then, built-in functions are not expected to support these numbers. The mathematics of density functions suggests that the probability of choosing something specific like pi to infinite digits in an infinite distribution is zero as 1/? is mathematically zero. I am curious what reason you have chosen to work on this problem and wonder if a more carefully chosen set of requirements meet your need. -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Daniel Lobo Sent: Monday, July 28, 2025 12:30 PM To: Rui Barradas <ruipbarradas at sapo.pt> Cc: r-help at r-project.org Subject: Re: [R] Drawing random numbers from Uniform distribution with infinite range 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 at 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guidehttps://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 at 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.
Ebert,Timothy Aaron
2025-Jul-29 00:12 UTC
[R] Drawing random numbers from Uniform distribution with infinite range
There are an infinite number of values between 0 and 1. Likewise between any two values, though it might get tricky if they were infinitely close together. The real numbers also go from negative infinity to positive infinity. Computers have limited memory that can handle a minute portion of this range. There is also an issue with random number generator. Most computer random number generators are pseudo-random. That is they are "random" with some range, but expanding beyond that range they show patterns. There are services that will provide true random numbers (e.g. https://www.random.org/), but there may be limits to the rate the numbers are generated or provided to you. "without preference of any particular probability distribution" but the Uniform distribution is a probability distribution. All computer numbers are discrete. If the computer can process 17 decimal places, then anything in the twentieth decimal place will be lost. If your computer can handle 30 decimal places, then anything in the fiftieth decimal place will be lost. This results in number gaps between consecutive values at the smallest significant digit. So even a Uniform distribution where every value has equal probability of being chosen is not true for values between consecutive least significant digit. Significant digits is not decimal places. 12345654678239543 is 17 digits as is. 0. 1234565467823954. However, 12345654678239543.1234565467823954 is 34 digits. Also, 123456546782395430000000 can be a stored number in the computer but if accuracy is 17 digits then the trailing zeros will always be zero (or some random noise). A program like R can handle very large and small numbers, but not every digit will be kept in memory. Things get more complex in that the computer must store things in binary. Not all real numbers have a finite binary equivalent. This can make a simple program give unexpected outcomes. options(digits=20) for (i in 1:100) { j <- 1 + 0.1^i if (j == 1) { cat("At i =", i, "-> 1 + 0.1^i == 1 (difference lost due to precision)\n") } else { cat("i =", i, "j =", j, "\n") } } Everything looks good up until options=16. At options=17 the results are different. There are programming strategies to overcome this limit, but there is still a limit. library(Rmpfr) precBits <- 256 # bits of precision (~77 decimal digits) for (i in 1:50) { small <- mpfr("0.1", precBits)^i j <- 1 + small if (j == 1) { cat("At i =", i, "j == 1 (even with high precision)\n") break } else { cat("i =", i, "j =", format(j, digits = 40), "\n") } } Eventually, you run out of computer memory. If this is a part of a large process the execution time may be long. Tim -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Daniel Lobo Sent: Monday, July 28, 2025 12:30 PM To: Rui Barradas <ruipbarradas at sapo.pt> Cc: r-help at r-project.org Subject: Re: [R] Drawing random numbers from Uniform distribution with infinite range [External Email] 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 at 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://st/ > > at.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7Ctebert%40ufl > > .edu%7Cef232b26cd0a45cb285f08ddcdf70798%7C0d4da0f84a314d76ace60a6233 > > 1e1b84%7C0%7C0%7C638893183054544956%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0 > > eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIs > > IldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=IraxT8iu7WasjesdmwC3KXg7qXjxaQJL > > WER%2FGenW%2BRs%3D&reserved=0 PLEASE do read the posting guide > > https://ww/ > > w.r-project.org%2Fposting-guide.html&data=05%7C02%7Ctebert%40ufl.edu > > %7Cef232b26cd0a45cb285f08ddcdf70798%7C0d4da0f84a314d76ace60a62331e1b > > 84%7C0%7C0%7C638893183054560855%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1h > > cGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldU > > IjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=%2FrlPXP%2BCnUQ1S5yBOBaf3zj71vrQYF9m > > cJ8woJ0QI60%3D&reserved=0 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.w/ > ikipedia.org%2Fwiki%2FContinuous_uniform_distribution&data=05%7C02%7Ct > ebert%40ufl.edu%7Cef232b26cd0a45cb285f08ddcdf70798%7C0d4da0f84a314d76a > ce60a62331e1b84%7C0%7C0%7C638893183054570228%7CUnknown%7CTWFpbGZsb3d8e > yJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWF > pbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=bimbtz4%2BHqya58n4A1CVpHsWZ4I > 1hoDq25gY7z81HII%3D&reserved=0______________________________________________ R-help at 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.
Richard O'Keefe
2025-Jul-29 20:53 UTC
[R] Drawing random numbers from Uniform distribution with infinite range
R can only represent representable numbers. The cardinality of the set of numbers that could be the result of sampling in R is some finite number a bit less than 2^64. It's not even countably infinite. The real line is UNcountably infinite. Almost no points on the real line can be represented. Second, any random selection from any set is going to be according to *some* probability distribution. The whole without any preference for any particular probability distribution" makes no sense. (Can you possibly be thinking of Bayesian 'improper priors'?) Bearing in mind the finiteness of representable numbers and the intrinsic necessity of having *some* probability distribution, why do you think you need to do this thing that cannot be done? On Tue, 29 Jul 2025 at 04:51, Daniel Lobo <danielobo9976 at gmail.com> 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 at 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 at 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 at 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.