1
$\begingroup$

Suppose I have a geometric distribution given which looks like this

enter image description here

Here p = 0.4 and x is from 0 to inf. Now what does it mean when one says generate a random number/variable using this distribution?

$\endgroup$
  • $\begingroup$ What programming language are you using? Do you know how to generate a number from the distribution you give in your example? $\endgroup$ – Peter O. Sep 17 at 10:27
  • $\begingroup$ i am using python and yes i can call the scipy.stats.geom.rvs function to generate a random number but i wanted to understand what it meant conceptually $\endgroup$ – afsara_ben Sep 17 at 10:34
  • $\begingroup$ a random number/variable is picked from within a range say 1 to 1000, but what does it mean to pick a number from a given distribution $\endgroup$ – afsara_ben Sep 17 at 10:35
  • 1
    $\begingroup$ In the terminology at stats.stackexchange.com/a/54894/919, generating a random number amounts to drawing one ticket from a box. $\endgroup$ – whuber Sep 17 at 14:31
7
$\begingroup$

In general, generating a random number from a probability distribution means transforming random numbers so that the numbers fit the distribution.

Perhaps the most generic way to do so is called inverse transform sampling:

  1. Generate a uniform random number in [0, 1].
  2. Run the quantile function (also known as the inverse CDF or the PPF) on the uniform random number.
  3. The result is a random number that fits the distribution.

However, this technique can't be used in practice for all distributions. The main reason is that the quantile function is either unavailable or hard to calculate. Thus, for many distributions, other techniques are used. They include rejection sampling, direct transformations, etc.

In the case of the geometric distribution, there are at least two ways to generate numbers that follow it. One way is a direct transformation:

  1. Set x to 0.
  2. With probability p, return x.
  3. Add 1 to x and go to step 2.

A geometric random number can also be found by inverse transform sampling, described below.

  1. Generate a uniform random number in [0, 1], call it u.
  2. Run the quantile function, which is floor(log((u - 1)/(p-1))/log(1-p)).
  3. The result is a geometric random number.

Other ways to generate geometric random numbers are available. The choice of algorithm depends on many things, including efficiency, simplicity, and accuracy. (Note that the geometric distribution is defined differently in different works.) The same applies to other probability distributions.

The 1986 book Non-Uniform Random Variate Generation by Luc Devroye goes into random generation from various distributions in detail. See also my article on randomization and sampling methods.

| cite | improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Although this answer describes various procedures to generate random numbers, it does not answer the question concerning what this process really means. $\endgroup$ – whuber Sep 17 at 14:30
  • 3
    $\begingroup$ @whuber: I answered this question while it was on Stack Overflow, a programming-oriented site; thus, it reflected what I believed the asker had in mind at the time I wrote it: what it means to code the random generation of the geometric and other distributions. $\endgroup$ – Peter O. Sep 17 at 15:19
  • 1
    $\begingroup$ Thank you for that clarification, @Peter. In light of that context, here's my +1 to you. $\endgroup$ – whuber Sep 17 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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