The uniform distribution models a random variable, X, that can take any value within the range [a, b] with equal probability.
The PDF is given by for a ≤ x ≤ b, and 0 otherwise.
The expectation and variance are given respectively by the following expressions:
A continuous uniform probability distribution is generated and plotted for various sample sizes in the following code:
In [11]: np.random.seed(100) # seed the random number generator # so plots are reproducible subplots = [111,211,311] ctr = 0 fig, ax = plt.subplots(len(subplots), figsize=(10,12)) nsteps=10 for i in range(0,3): cud = np.random.uniform(0,1,nsteps) # generate distrib count, bins, ignored = ax[ctr].hist(cud,15,normed=True) ax[ctr].plot(bins,np.ones_like(bins),linewidth=2, color='r') ax[ctr].set_title('sample size=%s' % nsteps) ctr += 1 nsteps *= 100 fig.subplots_adjust(hspace=0.4) plt.suptitle("Continuous Uniform probability distributions for various sample sizes" , fontsize=14)
The following is the output:
Continuous uniform distribution