Let $0 < p < 1$. Let $X$ be a random one of two objects, coded as $1$ and $2$ , where $\mathbb{P}(x=1)= p$ and $\mathbb{P}(x=2)=1-p$. State how inverse-transform sampling produces one random sample of $X$.
I know that if F is continuous and strictly increasing, the inverse CDF at $u \in (0,1)$ is the unque b solving the equation $F(b)=u$. So CDF$=F(b)=\mathbb{P}(x\leq b)= 1 - \mathbb{P}(x>b)$.
But I don't understand how inverse-transform sampling produces one random sample of for the given question.
Should it be like that?
The inverse-transform sampling procedure would be as follows:
$F(1)=p$ and $F(2)=1$ (since it's the maximum value a CDF can take).
The inverse CDF is such that $F^{-1}(u)=1$ if $u \leq p$ and $F^{-1}(u)=2$ if $p < u \leq 1$.
Generate a random number $u$ from a uniform distribution on (0,1). If $u \leq p$, output $X=1$; else, output $X=2$.