TITLE: What is "sampling from a distribution"?
QUESTION [5 upvotes]: Exercise 4.11.3 of Grimmett and Stirzaker's Probability and Random Processes reads "Use the rejection method to sample from the gamma density $\Gamma(\lambda,t)$ where $t (\geq 1)$ may not be assumed integral."
What exactly is this exercise asking for? More generally, what is meant by "sampling from a distribution" (or "sampling from a density")? Section 4.11 of the given textbook refers to "sampling" over and over, but doesn't define it. 
It seems, based on the examples, that it means to simply find a random variable with the given distribution. If that's correct, why is it called "sampling"?
Am I supposed to use a computer for this exercise?

REPLY [2 votes]: The question is asking you to devise a scheme to generate random numbers according to the specified distribution, Gamma$(\lambda, t)$. Formally, we are coming up with a way to construct a random variable (i.e. a measurable function from a probability space to the reals) with a predetermined distribution given only a sequence of independent random variables of predetermined distributions, using a particular method - in this case, so called "rejection sampling".  The usual rejection sampling algorithm to get samples from a distribution with density $f$, using another density $g$, is along the lines of this:

Sample $Y \sim g(y)$ from some candidate distribution, and $U \sim \mbox{Uniform}(0, 1)$ independently.
Accept $Y = X$ as a simulation from $f(x)$ if $U \le \frac{f(Y)}{Mg(Y)}$ where $M \ge \sup_x \frac{f(x)}{g(x)}$. 
Otherwise, go back to step 1, using random variables which are independent of those which have already been generated.

More precisely, we have sequences $Y_1, Y_2, ...$ and $U_1, U_2, ...$ of independent random variables on a probability space $(\Omega, \mathcal F, P)$, and if you undertake this algorithm for each fixed $\omega \in \Omega$ then the random variable $X$ can be shown to be distributed according to $f$, provided that the support of $g$ contains the support of $f$ and that such an $M < \infty$ exists. As Dider notes, we want our algorithm to terminate after a finite number of steps almost surely, and it can be shown that this one does. 
In the case of the Gamma distribution, you can take $g(y)$ to be another Gamma density that you know how to sample from, say Gamma$(\lambda', t')$ where $t'$ is integral. You can easily get draws from such a Gamma using only uniform random variables, and then turn them into draws from the Gamma$(\lambda, t)$ using the above method.