4
$\begingroup$

Functions like RandomInteger draw random variates from a finite range. Can one also obtain random natural numbers in case the range extends from 1 to infinity? If so, how can we produce a list of $n$ such numbers?

$\endgroup$
  • 7
    $\begingroup$ I'm voting to close this question as off-topic because it is based on a misunderstanding of the underlying mathematics, and thus it makes no sense. $\endgroup$ – Szabolcs Dec 21 '15 at 11:30
  • 2
    $\begingroup$ This is an interesting reading you might want to look at: askamathematician.com/2010/01/… $\endgroup$ – Szabolcs Dec 21 '15 at 11:35
  • 3
    $\begingroup$ I can't see anything wrong with the question. There are a variety of common (and not so common) discrete distributions that allow one to draw a random number from the set of numbers $\{1, 2, 3, ..., \infty\}$ ... including the Geometric, Lotka, Miller, Riemann Zeta, Simon, Yule etc. I have voted for the question to be re-opened. $\endgroup$ – wolfies Dec 21 '15 at 12:29
  • 2
    $\begingroup$ @wolfies well, I see a couple of issues with the question: spelling mistakes, and no mention of any requirements on the distribution. And, even though such distributions do exist, there are obvious practical obstacles to to actually producing a list of random variates from them. I fixed the spelling mistakes, but cannot do anything about the other problems. I also cast my reopen vote in the hope that you will give an answer that justifies the question, as incompletely specified as it is. $\endgroup$ – Oleksandr R. Dec 21 '15 at 13:31
  • 2
    $\begingroup$ With no specified critera for the distribution, RandomInteger[{1, 10},n] satisfies the requirement. (10 is just as far from infinity as any other number you might pick.). We should not be guessing about what sort of distribution you want. voting to close as off topic. $\endgroup$ – george2079 Dec 21 '15 at 18:30
17
$\begingroup$

There are any number of discrete statistical distributions defined on the natural set of numbers (positive integers): $$\{1,2,3, ..., \infty\}$$

Geometric

Perhaps the best known such distribution is the Geometric with pmf:

$$P(X=x) = p (1-p)^{x-1} \quad \text{for} \quad x = 1, 2, ...$$

with parameter $0<p<1$.

Mathematica's implementation of the geometric distribution uses an alternative defn that counts from 0. I was going to say that it is easy enough to create your own definition manually via:

geometricdist = ProbabilityDistribution[p*(1 - p)^(x - 1), {x, 1, Infinity, 1}]

and then generate some pseudorandom drawings via:

 RandomVariate[geometricdist /. p -> .1, 100]

but oddly this does not seem to work, and returns the error message:

RandomVariate::noimp: Sampling from ProbabilityDistribution[0.1 0.9^(-1+[FormalX]),{[FormalX],1,[Infinity],1}] is not implemented. >>

As a workaround, one can use $Mathematica$'s in-built GeometricDistribution (defined on $0, 1, 2 \dots$), and then transform it manually to the positive integers by simply adding 1 to the output. That seems to work fine, as per:

dataZ = RandomVariate[GeometricDistribution[.1], 1000] + 1

Logarithmic

An in-built distribution that can be used automatically is the Logarithmic distribution with pmf:

$$P(X=x) = -\frac{\lambda ^x}{x \log (1-\lambda )} \quad \text{for} \quad x = 1, 2, ...$$

which can be implemented as:

data = RandomVariate[LogSeriesDistribution[.8], 1000]

Alternative distributions that can be used are the:

  • Beta-Geometric

  • DiGamma

  • Gross-Miller

  • Haight Zeta

  • Logarithmic

  • Lotka

  • Miller

  • Prasad

  • Riemann Zeta

  • Schwarz-Tversky (Type 1)

  • Simon

  • Takacs

  • TriGamma and

  • Yule.

These are just examples from the '1 to Infinity' palette in the mathStatica add-on to Mathematica; conceptually, there are, of course, an infinite number of possible contenders.


The question turns out to be more interesting than I had expected, because it seems to raise the question as to whether Mma can generate pseudorandom drawings from $$\{1,2,3, ..., \infty\}$$ at least for custom distributions. The examples I have tried have so far proved unsuccessful.

It can easily be done, say here with mathStatica, for the same Geometric distribution:

        f = p (1-p)^(x - 1);             
 domain[f] = {x, 1, Infinity} && {0 < p < 1}  &&  {Discrete};

Then, generate 30 pseudorandom drawings with:

  RandomNumber[30, f /. p -> .1]

{14, 7, 4, 7, 12, 12, 7, 3, 2, 9, 10, 11, 1, 6, 2, 8, 4, 2, 4, 6, 3, 4, 37, 1, 1, 1, 5, 15, 24, 8}

As another example, here is a Schwarz-Tversky (Type 1) distribution with pmf:

        f = 4/(x(x+1)(x+2)); 
 domain[f] = {x, 1, Infinity} && {Discrete}; 

And here again are 100 pseudorandom drawings from it:

RandomNumber[100, f]

{1, 9, 1, 1, 1, 2, 2, 3, 4, 2, 4, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 19, 1, 1, 10, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, 1, 1, 4, 2, 1, 2, 1, 1, 1, 1, 1, 8, 7, 1, 1, 3, 1, 1, 1, 6, 1, 1, 39, 1, 4, 1, 1, 2, 3, 1, 5, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1}

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.