# Exponential Distribution Random Numbers out of range

Hi All I have following exponential distribution equation to generate different values for random variable 'r':

$$p_r = \frac{(1 - \alpha)\alpha^{CW}}{1 - \alpha^{CW}} \alpha^{-r} \text{ for } r = 1, \dots, CW$$

I have applied inverse sampling to get values of $$r$$ by equating this equation to random variable $$U$$ between 0 and 1 and then applying log on both sides. CW is fixed as 10 and $$\alpha$$ as 0.8 . But I get values of $$r$$ greater than CW (its max range) and values are positive and negative.

For convenience, use the shorthand $$\beta \equiv\frac{(1 - \alpha)\alpha^{CW}}{1 - \alpha^{CW}}$$.

Generate random variable $$U$$ uniformly from $$[0,1)$$, where the observed values are $$u$$, then the desired random variable $$R$$ (which observed values are $$r$$) can be obtained as

\begin{align} r &= 1 & &\text{if} & 0 \le \frac{u}{\beta} & < \alpha^{-1} \\ r &= 2 & &\text{if} & \alpha^{-1} \le \frac{u}{\beta} & < \alpha^{-1} + \alpha^{-2} \\ r &= 3 & &\text{if} & \alpha^{-1} + \alpha^{-2} \le \frac{u}{\beta} &< \alpha^{-1} + \alpha^{-2} + \alpha^{-3} \\ r &= 4 & &\text{if} & \alpha^{-1} + \alpha^{-2} + \alpha^{-3} \le \frac{u}{\beta} &< \alpha^{-1} + \alpha^{-2} + \alpha^{-3} + \alpha^{-4}\\ &\vdots &&\vdots &&\vdots \\ r &= k & &\text{if} & \sum_{j=1}^{k-1} \alpha^{-j} \le \frac{u}{\beta} &< \sum_{j=1}^k \alpha^{-j} \\ &\vdots &&\vdots &&\vdots \\ r &= CW & &\text{if} & \sum_{j=1}^{CW-1} \alpha^{-j} \le \frac{u}{\beta} &< \sum_{j=1}^{CW} \alpha^{-j} \end{align}

By the way, this is not an exponential distribution. It is a truncated Geometric distribution.

Your original approach of "applying log on both sides" is the method of inverse transformation that works only on continuous distributions when directly applied like that.

• 1. Thanks for explanation and sorry for late reply . This equation is from SIFT MAC Protocol research paper [Jamieson, K., Balakrishnan, H., & Tay, Y. C. (2006, February). Sift: A MAC protocol for event-driven wireless sensor networks. In European workshop on wireless sensor networks (pp. 260-275). Springer, Berlin, Heidelberg] and author says that it is exponential. any ways may be i understood wrong. 2. How can we make this equation more compact as i need to program it ? Dec 22, 2018 at 12:20
• (1) People from different fields use different terminology. If no such communication problem is encountered in your line of work then it's not my place to judge. Just FYI in many communities, Geometric Distribution and Exponential Distribution refer to two different things that are mutual analogues, with the former being discrete and latter continuous. Dec 23, 2018 at 10:39
• (2) This set of equations can be easily vectorized (coded compactly) in most commonly used programming languages or Matlab, R, Mathematica, etc. What platform are you working with? Dec 23, 2018 at 10:40
• I am working in C++. Dec 24, 2018 at 11:46
• Continue the two bullets above (1) I finally take a look at the (various versions) of the paper by Jamieson and Balakrishnan. They clearly stated that "Sift uses a truncated increasing geometric distribution". This and that are two highlighted snapshots. I don't know why you said they call it exponential. I advise you edit the question title, otherwise the suggested links are all irrelevant. Dec 25, 2018 at 11:50