I want to generate random variates from a truncated geometric distribution over the interval $[0, n)$ with specified expected value, $0 \le E < n$. The obvious way to do this seems to be to sample the exponential distribution over the same interval and round down to the nearest integer, but I've run into some technical difficulties, in (what I believe to be) decreasing order of seriousness:
I don't know how to truncate the distribution except by rejection sampling, but I cannot do that, because the surrounding code requires a constant-time operation.
I'm not confident that rounding an exponential variate down to the nearest integer gives the proper distribution of integers.
The obvious way to generate an exponential variate over $[0, n)$ in constant time is inverse transform sampling: $T = -E \log U$ where $E$ is the expected value and $U$ is a uniform variate over $(0, 1]$. However, on a real computer (using IEEE doubles for all calculations), this will not generate variates larger than $744.44E$, because $U$ cannot be smaller than approximately $5\times 10^{-324}$. In my application, the desired upper limit $n$ might be quite large. I'm not sure this is a problem, since variates larger than $744.44E$ should appear less than once in $2 \times 10^{323}$ trials, but I can't convince myself it's genuinely not a problem.
When $E=0$, the above equation always evaluates to zero. Is that the correct behavior?