What type of distribution would rand()/rand() produce?

308 Views Asked by At

If rand() is a function which produces a linearly distributed random number over a range not containing zero, then what type of distribution would rand() / rand() produce?

I know it would center at 1, and there would be a few extreme values very close to zero or very large.

Does this type of random distribution have a name?

2

There are 2 best solutions below

4
On

Let $U_1$ be a uniform random variable with domain $[a,b]$ for $b>a>0$, and let $U_2$ be another identically distributed independent uniform variable.

Let $X= \frac{U_1}{U_2}$. It is clear that $\frac{b}{a} \geqslant X \geqslant \frac{a}{b}$ with probability 1. Let $x$ be from such an interval. Then $$ \begin{eqnarray} F(x) &=& \mathbb{P}\left( X \leqslant x\right) = \mathbb{P}\left( U_1 \leqslant U_2 x \right) = \mathbb{E}\left( \min\left(1, \max\left(0, \frac{x U_2 - a}{b-a} \right) \right) \right) \\ & = & \int_0^1 \min\left(1, \max\left(0, \frac{x (a+(b-a) u) - a}{b-a} \right) \right) \mathrm{d} u \\ &=& \int_0^1 \min\left(1, \max\left(0, u \cdot x + \frac{a}{b-a} (x-1) \right) \right) \mathrm{d} u \\ \end{eqnarray} $$ Consider now two cases, $\frac{b}{a} \geqslant x \geqslant 1$ and $1 > x \geqslant \frac{a}{b}$.

  • $\frac{b}{a} \geqslant x \geqslant 1$, which implies $u \cdot x + \frac{a}{b-a} (x-1) > 0$:

$$ \begin{eqnarray} F(x) &=& \int_0^1 \min\left(1, \max\left(0, u \cdot x + \frac{a}{b-a} (x-1) \right) \right) \mathrm{d} u \\ &=& \int_0^1 \min\left(1, u \cdot x + \frac{a}{b-a} (x-1) \right) \mathrm{d} u \\ &=& \int_0^{u^\ast} \left( u \cdot x + \frac{a}{b-a} (x-1) \right) \mathrm{d} u + \int_{u^\ast}^1 \mathrm{d} u \\ &=& \left(\frac{u^\ast}{2} x - \frac{b - a x}{ x(b-a)}\right) u^\ast + 1 \\ &=& 1 - \frac{1}{2 x} \left( \frac{b-a x}{b-a} \right)^2 \end{eqnarray} $$ where $u^\ast$ solves $u x + \frac{a}{b-a} (x-1) = 1 $, i.e. $u^\ast = \frac{b-a x}{x (b-a)}$.

  • $1 > x \geqslant \frac{a}{b}$ implies $u \cdot x + \frac{a}{b-a} (x-1) < 1$: $$ \begin{eqnarray} F(x) &=& \int_0^1 \min\left(1, \max\left(0, u \cdot x + \frac{a}{b-a} (x-1) \right) \right) \mathrm{d} u \\ &=& \int_0^1 \max\left(0, u \cdot x + \frac{a}{b-a} (x-1) \right) \mathrm{d} u \\ &=& \int_{u_\ast}^1 \left(u \cdot x + \frac{a}{b-a} (x-1) \right) \mathrm{d} u \\ &=& x \left( \frac{1}{2}- \frac{u_\ast^2}{2} \right) + \frac{a}{b-a} (x-1) \left( 1- u_\ast \right) \\ &=& \frac{ (a- b x)^2}{2 (b-a)^2 x} \end{eqnarray} $$ where $u_\ast$ solves $ u \cdot x + \frac{a}{b-a} (x-1) = 0$, i.e. $u_\ast = \frac{a}{b-a} \frac{1-x}{x}$.

Given $F(x)$ computed above, the probability density follows by differentiation.

0
On

If your interval is $(a,b)$, then look at the square $U=(a,b)\times(a,b)$. If $\frac{b}{a}\geq z\geq 1$, then the subspace of $U$ such that $x/y>z$ is just a lower right triangle of $U$ going from $(az,a)$ to $(b,a)$ to $(b,\frac{b}z)$. This has area equal to $\frac{(b-az)(\frac{b}z - a)}2 = \frac{(b-az)^2}{2z}$. So if $g(z)=p(x/y>z) = \frac{(b-az)^2}{2z(b-a)^2}$, then the distribution should be $-g'(z)$ for $z>1$.

This gives a distribution of $\frac{\frac{b^2}{z^2}-a^2}{2(b-a)^2}$ for $z\geq 1$.

For $\frac{a}{b}<z\leq 1$, we do a similar computation to show that:

$$p(\frac{x}{y}<z) = \frac{(bz-a)^2}{2z(b-a)^2}$$

The derivative gives us the distribution for these $z$, so the value is here is:

$$\frac{b^2-\frac{a^2}{z^2}}{2(b-a)^2}$$

So the result is: $$\frac{b^2-\frac{a^2}{z^2}}{2(b-a)^2}\text {when }\frac{a}b \leq z\leq 1$$ and $$\frac{\frac{b^2}{z^2}-a^2}{2(b-a)^2}\text{ when }1\leq z \leq \frac{b}a$$