Richard O'Keefe
2025-Jul-29 20:44 UTC
[R] Drawing random numbers from Uniform distribution with infinite range
The uniform distribution with infinite range gives each possible answer infinitesimal probability of being chosen. In the standard real numbers, that probability is ZERO. In fact, the probability of getting a number in *any* prespecified finite range is the same, ZERO. One such finite range is the numbers that can be represented in floating-point. So you are with certainty not going to draw a representable number. A complete answer to your question is thus ifelse(runif(N) < 0.5, 1, -1)/0 Why do you think you need this? On Tue, 29 Jul 2025 at 04:01, Daniel Lobo <danielobo9976 at gmail.com> 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.
Duncan Murdoch
2025-Jul-29 20:48 UTC
[R] Drawing random numbers from Uniform distribution with infinite range
On 2025-07-29 4:44 p.m., Richard O'Keefe wrote:> The uniform distribution with infinite range gives each possible > answer infinitesimal probability of being chosen.That's also true of a finite range uniform distribution.> In the standard real numbers, that probability is ZERO.So is that.> In fact, the probability of getting a number in *any* prespecified > finite range is the same, ZERO.That's not true for the finite range version, only the improper one. Duncan Murdoch> One such finite range is the numbers that can be represented in floating-point. > So you are with certainty not going to draw a representable number. > A complete answer to your question is thus > ifelse(runif(N) < 0.5, 1, -1)/0 > > Why do you think you need this? > > > On Tue, 29 Jul 2025 at 04:01, Daniel Lobo <danielobo9976 at gmail.com> 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. > > ______________________________________________ > 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.