Uniform Random Variables and Uniform Distribution

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.33 out of 5)

Continuous Uniform Random Variables:

Continuous Uniform Random Variables are used to model a scenario where a continuous random variable can take values that are equally distributed (with equal probability) in an interval. Uniform distribution is the underlying distribution to model such random variables.

A continuous uniform distribution is denoted by

$$X \sim \mathcal{U}(a,b) \text{, with a} \leq b $$

Here \( a\) and \(b\), are limits of the interval over which the distribution is effectively defined.

Probability Density Function

The Probability Density Function (PDF) of the continuous uniform random distribution defined above is given by
$$ f_X(x) = \begin{cases} \frac{1}{b-a} & \text{ if } a \leq x \leq b \\ 0 & \text{ otherwise} \end{cases}$$

This equation indicates that the distribution when used, generates values in the interval (a,b) with equal probability (with probability \( \frac{1}{b-a}\))

Continuous Density Function

The Continuous Density Function (CDF) can be derived from the above PDF using the relation

$$ F_X(x) = \int_{-\infty }^{x}f_X(t)dt$$

Therefore, the CDF of the continuous uniform distribution is given by,

$$F_X(x) = \begin{cases} 0 & \text{ if } x < a \\ \frac{x-a}{b-a} & \text{ if } x \in \left[ a,b \right) \\ 1 & \text{ if } x \geq b \end{cases} $$

Plotting the PDF and CDF,

Uniform Distribution (Continous)
PDF and CDF of Continuous Uniform Distribution (Continous)

Discrete Uniform Random Variable:

Discrete Uniform Random Variables are used to model a scenario where a discrete random variable can take values that are equally distributed (with equal probability) in an interval. The underlying discrete uniform distribution is denoted by
$$ X \sim \mathcal{U}(\mathcal{S}) $$

Where\( \mathcal{S} \) is a finite set of discrete points on the real line. Meaning that each element in the finite set are equally likely.


“Rolling a fair die” can be considered as an experiment to generate uniform integers in the range 1 to 6. Since rolling of a fair die give only one of the six possible integer values (1,2,3,4,5,6), it is an experiment that generates discrete values. Since all the values in a fair die are equally likely (with probability of getting each value =1/6) it can be modelled using a discrete uniform distribution.

For a die, the set \( \mathcal{S} \) can take values \(\{1,2,3,4,5,6\}\)

Probability Mass Function (PMF):

If \( \mathcal{S} = \left\{ s_1, \cdots ,s_n \right\} \in \mathcal{Z} \) , then the due to the definition of uniform distribution, each element in the set are equally probable. Therefore,
\( Prob \left[X=s_1 \right]=Prob \left[X=s_2 \right]=\cdots=Prob \left[X=s_n \right]=\frac{1}{n}\)

Then the PMF can be given by,

$$ f_X(x) = \begin{cases} \frac{1}{n} & x \in \left\{s_1,s_2 \cdots , s_n \right\} \\ 0 & otherwise \end{cases}$$

For rolling a fair die, the PMF simplifies as follows
$$ f_X(x) = \begin{cases} \frac{1}{6} & x \in \left\{1,2,3,4,5,6 \right\} \\ 0 & otherwise \end{cases}$$

The PMF and CDF for a discrete uniform random distribution is shown below

PMF and CDF of discrete uniform random variable
PMF and CDF of Discrete Uniform Distribution

Generating Uniform Random Numbers in Matlab:

Generating Continuous Uniform Random Numbers:

In Matlab “rand” function is used to generate continous uniform random numbers in the range [0,1].
rand function is used to pick any number in the interval [0,1] in which all the numbers in the interval are equally likely.

rand(n,m) will generate a matrix of size nxm. A trial run at my system gave the following results

To generate a random number in the interval [a,b] one can use the following code

a + (b-a)*rand(n,m); %Here nxm is the size of the output matrix

For example, to generate a matrix of size \(3 \times 4\) using uniform distribution in the interval [2,10]

Testing Uniformity:

To test whether the numbers generated by the uniform distribution are uniform in the interval [a,b], one has to generate very large number of values using the rand function and then plot the histogram

Testing the uniformity of rand function in the interval [2,10]

The histogram plot given below shows that the numbers in the range [2,10] are generated with almost equal probability.

Histogram of Uniform Distribution
Histogram of Uniform Distribution

Generating Discrete Uniform Random Numbers:

The same “rand” function can be used to generate discrete random numbers that follow discrete uniform distribution. The code to generate uniformly distributed discrete numbers from the set \( \mathcal{S}=\left\{1,2,3,…,n\right\}\) is given below.

To model rolling of a fair die, the sample space \( \mathcal{S}=\left\{1,2,3,4,5,6\right\}\). A roll of the die should generate a number from the sample space with equal probability. This single event can be modelled in matlab as

(The uniformity test for discrete random numbers can be done using the same code given above in the previous section)

Note:There is one more function in Matlab called “randn”. This function is used to generate random numbers that are normally distributed.


[1] Matlab Documentation entry on generating Uniformly distributed pseudorandom numbers using rand function

See Also:

[1] Introduction to Random Variables, PDF and CDF
[2] Chi-Squared distribution
[3] Derivation of Error Rate Performance of an optimum BPSK receiver in AWGN channel
[4] Eb/N0 Vs BER for BPSK over Rician Fading Channel
[5] BER Vs Eb/N0 for QPSK modulation over AWGN
[6] BER Vs Eb/N0 for 8-PSK modulation over AWGN
[7] Simulation of M-PSK modulation techniques in AWGN channel
[8] Performance comparison of Digital Modulation techniques

Recommended Books

More Recommended Books at our Integrated Book Store