# Density of $Y\sim \text{Unif}(0,X)$ where $X\sim \text{Unif}(0,a)$

As the title says, I'm trying to find the probability density function of $$Y\sim \text{Unif}(0,X)$$ where $$X\sim \text{Unif}(0,a)$$ and $$a>0$$.

Since both variable are uniformly distributed, I know $$p_X(x) = \frac{1}{a}$$ and that the conditional pdf of $$Y$$ given $$X=x$$ is $$p_Y(y \mid X=x) = \frac{1}{x}$$.

I'm computing $$$$p_Y(y) = \int_{-\infty}^{\infty} p_X(x) \: p_Y(y \mid X=x) dx = \int_{0}^{a} \frac{1}{a} \frac{1}{x} dx = \frac{1}{a} \int_{0}^{a} \frac{1}{x} dx$$$$

but $$\frac{1}{x}$$ is not integrable in the interval $$[0,a]$$. What am I overlooking?

I'm asking this because for a side project I'm intuitively generating a skewed distribution in $$[0,a]$$ by doing random(0,random(0,2)) but was curious to prove what the resulting distribution would analytically be.

• Perhaps you could try shifting the distribution to the right, so that $X$ is uniform on $(1,a+1)$ and $Y$ on $(1,X)$. $p_X(x)$ would be the same and $\frac{1}{x}$ would be integrable in $[1,a+1]$. May 12, 2021 at 16:55
You need to consider the fact that $$Y$$ is always less than $$X$$. The conditional density is actually $$f_{Y|X}(y|x) = \begin{cases} \frac{1}{x} & 0 < y < x The marginal density then becomes: $$f_Y(y) = \frac{1}{a} \int_y^a \frac{1}{x} \: dx = \frac{\log(a) - \log(y)}{a}$$
$$p(y \mid X=x)$$ is $$\frac{1}{x}$$ only when $$0 < y < x$$. So the integral with respect to $$x$$ should actually be $$\int_y^a$$ instead of $$\int_0^a$$.