# Truncated Geometric Distribution

I have equation for truncated increasing geometric distribution given as $$pr=\frac{ (1-\alpha) \alpha^{CW}} { 1- \alpha^{CW} }. \alpha^{-r}$$ with $$r=1, ....., CW$$. $$\alpha$$ is parameter we can set between 0 and 1.

Here probability of picking r=1 is very low and r=CW is very high. How can i derive an equation from this equation that should give me values generated between r= 1 and CW with given distribution.
i should get values like this if r=1 to 10. CW=10 10,10,9,9,6,1,6,10,10,3,4 (following geometric distribution from equation provided)

The standard way to generate a geometric variable with probability mass function $$P(n)=(1-p)p^n$$ for $$n\in\mathbb N_0$$ from a variable $$u$$ uniformly distributed over $$[0,1]$$ is

$$n=\left\lfloor\frac{\log u}{\log p}\right\rfloor\;.$$

To restrict to $$0\le n\lt CW$$, we need to transform $$u$$ to $$[u_0,1]$$ such that $$\frac{\log u_0}{\log p}=CW$$. Thus $$u_0=p^{CW}$$, so you can use $$u\to 1-u\left(1-p^{CW}\right)$$, and the formula for generating $$n$$ becomes

$$n=\left\lfloor\frac{\log\left(1-u\left(1-p^{CW}\right)\right)}{\log p}\right\rfloor\;.$$

To map this to your case, take $$r=CW-n$$ and $$p=\alpha$$.

• Thanks for the answer, what is $u(1-p^{cw} )$. How can I calculate it, is it random number? What is it's range? Feb 1, 2020 at 18:07
• @user3696623: I'm not sure I understand the question. I didn't introduce any lowercase $cw$, I just used the uppercase $CW$ that you introduced yourself, so I can't speak to that. As to $p$ and $u$, I introduced them in the answer: $p=\alpha$, and $u$ is a variable uniformly distributed over $[0,1]$. So I'm not sure what's unclear. Is the problem that I omitted the implicit "random" in front of "variable uniformly distributed over $[0,1]$"? Feb 1, 2020 at 21:23
• Sorry i did't understand correctly, In equation for $n$ that you have mentioned the numerator contains $log( 1-u(1-p^{cw} ) )$, so is it uniform distribution between $(0, 1-p^{cw})$ inside $log$ so would numenator be $\log(1-u(0, 1-p^{CW})$ Feb 2, 2020 at 6:59
• @user3696623: We seem to be talking past each other. Again I don't understand your question. What are you denoting by $u(0,1-p^{CW})$? In my notation, $u$ is a real-valued random variable, so $u(0,1-p^{CW})$ makes no sense. The argument $1-u(1-p^{CW})$ is uniformly distributed not over $[0,1-p^{CW}]$ but over $[p^{CW},1]$, as advertised in the preceding text. It must be since $n=0$ is one of the possible values to be generated, so the range of the argument must extend to $1$. Feb 2, 2020 at 9:18
• Thanks alot, Yes i was mistakenly not printing r but n. I thank you once again for your support. I have some other questions, that i will post soon, and i hope people like you will keep helping us Feb 2, 2020 at 17:15