# Uniform distribution

In mathematics, the uniform distributions are simple probability distributions. The distribution can be either discrete or continuous. In the discrete case, they can be characterized by saying that all possible values are equally probable. In the continuous case one says that all intervals of the same length are equally probable.

## The discrete case

A random variable that has any of n possible values x1, x2, ..., xn that are equally probable has a discrete uniform distribution, then the probability of any outcome xi is 1/n. A simple example of the discrete uniform distribution is throwing a fair die. The possible values of x are 1, 2, 3, 4, 5, 6; and each time the die is thrown, the probability of a given score is 1/6.

In case the values of a random variable with a discrete uniform distribution are real, is possible to express the cumulative distribution function in terms of the degenerate distribution, thus

$F(x)={1\over N}\sum_{i=1}^N\theta(x-x_i)$

where the Heaviside step function θ(x) is the CDF of the degenerate distribution at x = 0.

## The continuous case

In the continuous case, the uniform distribution is also called the rectangular distribution because of the shape of its probability density function (see below). It is parameterised by the smallest and largest values that the uniformly-distributed random variable can take, a and b. The probability density function of the uniform distribution is thus:

$ p(x)=\left\{\begin{matrix} \frac{1}{b - a} & \ \ \ \mbox{for }a \leq x \leq b \\ 0 & \mbox{elsewhere} \end{matrix}\right. $

and the cumulative distribution function is:

$ F(x)=\left\{\begin{matrix} 0 & \mbox{for }x < a \\ \frac{x - a}{b - a} & \ \ \ \mbox{for }a \le x < b \\ 1 & \mbox{for }x \ge b \end{matrix}\right. $

The graph of the probability density function for the continuous uniform distribution looks like:

The continuous uniform probability density function

For a random variable following this distribution, the expected value is (a + b)/2 and the standard deviation is (b - a)/√12.

This distribution can be generalized to more complicated sets than intervals. If S is a Borel set of positive, finite measure, the uniform probability distribution on S can be specified by saying that the pdf is zero outside S and constantly equal to 1/K on S, where K is the Lebesgue measure of S.

### The standard uniform distribution

The standard uniform distribution is the continuous uniform distribution with the values of a and b set to 0 and 1 respectively, so that the random variable can take values only between 0 and 1.

### Sampling from a uniform distribution

When working with probability, it is often useful to run experiments such as computational simulations. Many programming languages have the ability to generate pseudo-random numbers which are effectively distributed according to the standard uniform distribution.

If u is a value sampled from the standard uniform distribution, then the value a + (b - a)u follows the uniform distribution parametrised by a and b, as described above. Other transformations can be used to generate other statistical distributions from the uniform distribution. (see uses below)

### Uses of the uniform distribution

In statistics, when a p-value is used as a test statistic for a simple null hypothesis, and the distribution of the test statistic is continuous, then the test statistic is uniformly distributed between 0 and 1 if the null hypothesis is true.

Although the uniform distribution is not commonly found in nature, it is particularly useful for sampling from arbitrary distributions.

A general method is the inverse transform sampling method, which uses the cumulative distribution function (CDF) of the target random variable. This method is very useful in theoretical work. Since simulations using this method require inverting the CDF of the target variable, alternative methods have been divised for the cases where the CDF is not known in closed form. One such method is rejection sampling.

The normal distribution is an important example where the inverse transform method is not efficient. However, there is an exact method, the Box-Muller transformation, which uses the inverse transform to convert two independent uniform random variables into two independent normally distributed random variables.it:variabile casuale Uniforme discreta de:Laplace-Verteilung