Welcome to our next lesson in the Probability and Statistics course. In our previous sessions, we focused on descriptive statistics, learning how to summarize datasets using measures of central tendency, dispersion, and shape (skewness and kurtosis). We were describing data that had already been collected. Today, we make a pivotal shift from describing the past to modeling the future. We will introduce the foundational concept of a random variable, which allows us to build mathematical models for uncertain events.
This lesson is designed to address a core component of your syllabus and is crucial for your upcoming exam. We will define what a random variable is, focusing specifically on the discrete case. Then, we will learn how to construct and interpret two essential functions that describe its behavior: the Probability Mass Function (PMF) and the Cumulative Distribution Function (CDF). Your goal is to move from confusion to confidence in solving problems with these tools, and we will do this through clear definitions and step-by-step worked examples.
1. From Outcomes to Numbers: The Random Variable
In many experiments, we are not interested in the raw outcomes themselves, but rather in a numerical property of those outcomes. For instance, if we flip a coin three times, we might not care about the specific sequence (e.g., HTH), but rather about the total number of heads (2).
A random variable is a function that assigns a numerical value to each outcome in the sample space of a random experiment. It's a variable whose value is a numerical outcome of a random phenomenon. In your computer science studies, you can think of it as a function that maps the set of possible outcomes to the set of real numbers.
We denote random variables with capital letters like , , and .
The following video provides an excellent, intuitive introduction to this idea.
02 - Random Variables and Discrete Probability Distributions
This video from Math and Science clearly explains the concept of a random variable and distinguishes it from a regular algebraic variable. It also introduces the idea of a probability distribution.
Please watch the first segment that defines a random variable. Then, watch the explanation of what a probability distribution is. Finally, watch the section that explains what makes a random variable "discrete".
As the video explains, random variables can be of two main types:
- Discrete Random Variable: Can only take on a finite or countably infinite number of distinct values (e.g., integers). Examples include the number of heads in three coin flips (can be 0, 1, 2, or 3), or the number on a rolled die (can be 1, 2, 3, 4, 5, or 6).
- Continuous Random Variable: Can take on any value within a given range. Examples include the height of a person or the exact temperature of a room.
This lesson focuses exclusively on discrete random variables. We will cover continuous variables in our next lesson.
2. The Probability Mass Function (PMF)
Once we have a discrete random variable , we need a way to describe the probability of it taking on each of its possible values. This is the job of the Probability Mass Function (PMF).
The PMF, denoted as or simply , gives the probability that the random variable is exactly equal to some value .
The following image provides a simple, clear example of mapping an experiment's outcomes to a random variable and then finding its PMF.

A valid PMF must satisfy two key properties:
- Non-negativity: for all possible values of . A probability can't be negative.
- Sum to one: The sum of the probabilities for all possible values of must be exactly 1.
This just means that the random variable has to take on one of its possible values.
Worked Example: Constructing a PMF
Let's walk through the process of constructing a PMF, which is a common exam-style task. The Math and Science video you watched earlier has a fantastic, step-by-step example using three coin flips.
02 - Random Variables and Discrete Probability Distributions
This video segment demonstrates precisely how to build a PMF from scratch for the experiment of flipping three coins, which is a classic problem.
Watch the detailed walkthrough from this example. Pay close attention to how the instructor: Lists all 8 possible outcomes in the sample space. Defines the random variable X as the number of heads. Counts how many outcomes correspond to each value of X (0, 1, 2, 3). Calculates the probability for each value of X to create the PMF table. After that, watch the short segment from sum of probabilities, which confirms that the probabilities in the PMF table add up to 1.
This process is your fundamental recipe for any problem that asks you to derive a PMF from an experiment:
- Identify the sample space (all possible outcomes).
- Define the random variable in terms of the outcomes.
- Determine the possible values that can take.
- For each possible value , count the number of outcomes that result in .
- Divide this count by the total number of outcomes to find .
3. The Cumulative Distribution Function (CDF)
While the PMF tells us the probability of being exactly a certain value, we often need to know the probability of being less than or equal to a certain value. This is given by the Cumulative Distribution Function (CDF).
The CDF, denoted , is defined as:
For a discrete random variable, you calculate the CDF at a point by summing up the PMF values for all possible outcomes less than or equal to :
The following video provides a clear, problem-based demonstration of how to derive the CDF from a PMF we've already found.
Probability Mass Function and Cumulative Distribution Function - Example 1
This video from Learning OnDemand continues with the same "three coin flips" example to show how to build the CDF table directly from the PMF.
Watch the segment explaining the CDF calculation. Notice the key difference in definition—P(X \le x) versus P(X=x)—and how each CDF value is a running total of the PMF probabilities.
Properties and Graph of the CDF
The CDF has several important properties:
- It is a non-decreasing function: if , then .
- (The probability of getting a value less than negative infinity is zero).
- (The probability of getting a value less than positive infinity is one).
For a discrete random variable, the graph of the CDF is a step function. It is flat between the possible values of the random variable and then "jumps" up at each value. The height of each jump at a value is exactly equal to the PMF value at that point, .

From this, you can see a vital relationship: you can recover the PMF from the CDF. The probability of a specific value is the size of the jump at :
Where is the value of the CDF just to the left of .
4. Practice Problems
Your primary goal is to master the calculations for your exam. The best way to do this is by working through problems. The following resource contains several excellent solved problems.
3.1.6 Solved Problems: Discrete Random Variables
This webpage provides several worked examples that are perfect for practice. We'll focus on two.
First, review the problem under the heading "Let X be a discrete random variable...". Here, the PMF is given to you. Follow the step-by-step solutions for calculating P(X \le 0.5), P(0.25 < X < 0.75), and a conditional probability. This tests your ability to use a PMF. Next, examine the problem "I roll two dice...". Focus on part 4, where a new random variable Z=X+Y is defined. The solution shows how to derive the PMF of Z. This is a classic example of combining random variables.
To further strengthen your skills, I recommend trying the following exercises on your own. The resource provides solutions for you to check your work.
This PDF contains a set of exercises at the end of the chapter. Working through these is excellent preparation for your exam.
Navigate to the "Exercises" section at the end of the chapter. I suggest you try: Exercise 5.2: This problem involves winnings and losses, a common application. You'll need to define the random variable for your winnings and find its PMF. Exercise 5.9: Here, you are given a PMF and asked to find its expected value, variance (which we'll cover in more detail soon), and plot its CDF. Focus on the CDF plotting part. The solutions are provided in the final section of the document, so you can verify your methods.
Conclusion
In this lesson, we made the crucial transition from descriptive statistics to the fundamentals of probability modeling. You learned how a random variable provides a numerical summary of a random experiment's outcomes. For discrete random variables, we defined two critical functions:
- The Probability Mass Function (PMF), , which gives the probability of each distinct outcome. Key properties: all probabilities are non-negative and they sum to 1.
- The Cumulative Distribution Function (CDF), , which gives the accumulated probability up to a certain value. Key properties: it's a non-decreasing step function that goes from 0 to 1.
By working through the examples of coin flips and dice rolls, you have practiced the essential skill of deriving these functions, which is exactly what you'll need for your exam.
In our next lesson, we will build directly on these concepts and extend them to continuous random variables. We'll see that while we can no longer assign a probability to a single point, we can use a Probability Density Function (PDF) and integration to find probabilities over intervals.