# Why is probability density funciton equal to 1 between 0 and 1?

I think I don't get the probability density function. At least on uniform distribution.

There are infinitely many numbers between $$0$$ and $$1$$, in probability, I understand this means that the weight it assigns to individual points must necessarily be zero. For this reason, we represent a continuous distribution with a probability density function (pdf) such that the probability of seeing a value in a certain interval equals the integral of the density function over the interval.

Then I don't get why, in this book page 74, the density function for the uniform distribution is just:

def uniform_pdf(x):
return 1 if x >= 0 and x < 1 else 0


Shouldn't it be:

def uniform_pdf(x):
return x if x >= 0 and x < 1 else 0

• Using the second distribution definition violates the nature of the uniform distribution; any two intervals $(a,b)$ and $(c,d)$ of equal length inside $[0,1]$ must receive the same probability. Oct 24, 2019 at 23:40
• With your pdf, is the probability of being below $\frac12$ equal to $\int\limits_0^{1/2} x \, dx = \frac18$ ? Or $\int\limits_0^{1/2} 1 \, dx = \frac12$ ? Oct 24, 2019 at 23:41
• You seem to be thinking of the distribution, rather than the density. Oct 25, 2019 at 0:05

As you write, " the probability of seeing a value in a certain interval equals the integral of the density function over the interval." For the uniform distribution, the probability of seeing a value in the interval $$[a,b]$$ ($$0\le a\le b\le1$$) is $$b-a$$, and this agrees with $$\int_a^b1\,dx$$, not with $$\int_a^bx\,dx$$.