1
$\begingroup$

Generic method

  1. Generate $U \sim \mathrm{Uniform}(0,1)$.
  2. Return $F^{-1}(U)$.

So, in step 1, $U$ has domain/support as $[0,1]$, so it is possible that $U=0$ or $U=1$, but $F^{-1}(0)=-\infty$. Should I reject the value $U=0$ and $U=1$ before applying step 2?

For example, discrete distribution sampling: $X$ takes on values $x_1, x_2, x_3$ with probability $p_1,p_2,p_3$

  1. Generate $U \sim \mathrm{Uniform}(0,1)$.
  2. Find the smallest $k$ such that $F(x_k)\geq U$ ($F$ is the CDF).

However, if $U=0$, and $p_1=0$, $k$ would be $1$. It could generate $x_1$ though its probability $p_1=0$. Is it acceptable?

  • 0
    @HenningMakholm Yes, my mistake. I was thinking about pseudorandom _linear feedback shift registers_ for which the state is always nonzero (unless it is "seeded" with all zeros and thus stays in that state forever) but writing about linear congruential generators.2012-03-03

1 Answers 1

1

In theory, it doesn't matter: the event $U=0$ occurs with probability $0$, and can thus be ignored. (In probabilistic jargon, it almost never happens.)

In practice, it's possible that your PRNG may return a value that is exactly $0$. For a reasonably good PRNG, this is unlikely, but it may not be quite unlikely enough for you to bet that it never happens. Thus, if your program would crash on $U=0$, a prudent programmer should check for that event and generate a new random number if it occurs.

(Note that many PRNG routines are defined to return values in the range $0 \le U < 1$: for example, the Java default PRNG is defined to return values of the form $m\cdot2^{-53}$ for $m \in \{0,1,\dotsc,2^{53}-1\}$. If you're using such a PRNG, a cheap but effective way to avoid the case $U=0$ is to use the number $1-U$ instead of $U$.)