Random Variables: Definition and Types
What you'll learn: How random variables transform outcomes from experiments into numbers we can analyze mathematically.
What Is a Random Variable?
A random variable is a function that assigns a numerical value to each possible outcome of a random experiment. Think of it as a translator: it takes outcomes (which might be words, colors, or any other form) and converts them into numbers we can work with mathematically.
For example, if you flip three coins, the outcomes are sequences like HHT, HTH, THH, etc. You could define a random variable X as "the number of heads." Now instead of tracking eight different sequences, you're working with numbers: 0, 1, 2, or 3 heads.
Why This Matters in Computer Science
Random variables let us quantify uncertainty in algorithms. When analyzing randomized quicksort, we might define X as "the number of comparisons performed." When testing network reliability, Y might be "the number of failed packets." By converting outcomes to numbers, we can calculate probabilities, expected values, and make informed design decisions.
Two Types of Random Variables
Discrete Random Variables
A random variable is discrete if it can only take on countable values (often integers). Examples:
- Number of bits flipped in a bitstring
- Count of users accessing a server
- Number of loop iterations before termination
The gaps between values matter here—you can have 5 or 6 requests, but never 5.7 requests.
Continuous Random Variables
A random variable is continuous if it can take on any value within an interval. Examples:
- CPU temperature (could be 67.3°C, 67.31°C, etc.)
- Time until system failure
- Network latency measurements
These variables have infinite precision within their range.
Key Takeaway: Random variables are functions mapping experiment outcomes to numbers; discrete random variables take countable values, while continuous ones span intervals with infinite precision.