Generate integer from 0 to 1 with equal probability
Yes, this is exactly rejection sampling and it works in the way you think it works, assuming that your initial procedure gr_04() generates the numbers $0$&ndash;$4$ with equal probability (you say it's random but you don't say it's uniform).

If $X$ is distributed uniformly on $\{0, \dots, 4\}$, then $\Pr(x\in\{0,1\}) = \Pr(x\in\{2,3\}) = 2/5$. With probability $1/5$, you'll have to try again but, on your second attempt, the probability of getting $0$ or&nbsp;$1$ is still equal to the probability of getting $2$ or&nbsp;$3$.  The number of attempts you have to make before you get something in $\{0, \dots, 3\}$ is just a geometric random variable with parameter $p=4/5$ and this has expectation $(1-p)/p = 1/4$ so, on average, you'll have to make $5/4$ calls to gr_04(), including the one that succeeds.

The analysis of your second example is similar: your procedure generates each possible answer with the same probability and each attempt succeeds with probability $7/8$, so you'll need an average of $8/7$ calls to gr_01(), which means an average of $(8/7)(5/4)=10/7$ calls to gr_04().