TITLE: CDF related to sampling with replacement
QUESTION [5 upvotes]: Consider a random process where integers are sampled uniformly with replacement from $\{1...n\}$.  Let $X$ be a random variable that represents the number of samples until either a duplicate is found or both the values $1$ and $2$ have been found.  So if the samples where $1,6,3,5,1$ then $X=5$ and if it was $1,6,3,2$ then $X=4$.  
How does one find the cumulative distribution function. That is how does one find $P(X \geq x)$?

REPLY [7 votes]: Let $x\geqslant1$. There are $n^x$ samples of length $x$. Amongst these, $(n)_x=\frac{n!}{(n-x)!}$ samples have no duplicate. 
A sample of length $x$ without duplicate where two distinct given results $i$ and $j$ appear is uniquely described by a sample of length $x-2$ without duplicate where neither result $i$ nor result $j$ appear, and the choice of a position amongst $x-1$ where one places result $i$, and the choice of a position amongst $x$ (once result $i$ is placed) where one places result $j$. There are $x(x-1)\cdot(n-2)_{x-2}$ of these samples. 
Thus, the number $S_x$ of samples of length $x$ without duplicate where results $i$ and $j$ do not both appear is
$$
S_x=(n)_{x}-x(x-1)\cdot(n-2)_{x-2},
$$
and, for every $x\geqslant0$,
$$
\mathbb P(X\gt x)=n^{-x}S_x=\frac{n!}{(n-x)!\,n^x}\left(1-\frac{x(x-1)}{n(n-1)}\right).
$$