1. Home
  2. Explore
  3. Computer Science
  4. Continuous Random Variables

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Continuous Random Variables

Discrete and Continuous Random Variables

This set of notes covers the transition from discrete random variables (binomial, Poisson, geometric, negative binomial) to continuous random variables, including the probability density function (PDF), cumulative distribution function (CDF), uniform distribution, and exponential distribution. The emphasis is on understanding the story behind each distribution, its parameters, range, PMF/PDF, expectation, and variance, so that new random variables can be learned and applied quickly without deriving all mathematics from scratch.


Review of Discrete Random Variables

Binomial Random Variable

  • Story: Number of successes in n independent trials, each with same probability of success p (e.g., number of heads in n coin flips).

  • Parameters: n (number of trials), p (probability of success).

  • Range: 0, 1, 2, \dots, n.

  • Probability Mass Function (PMF):

    P(X=k)=(nk)pk(1−p)n−kP(X = k) = \binom{n}{k} p^k (1-p)^{n-k}P(X=k)=(kn​)pk(1−p)n−k
  • Expectation: \mathbb{E}[X] = np

  • Variance: \text{Var}(X) = np(1-p)

Bernoulli Random Variable

  • Story: Binomial with n=1 – a single trial.

  • Parameters: p (probability of success).

  • Range: 0, 1.

Poisson Random Variable

  • Story: Number of events occurring in a fixed interval of time (or space) when events happen at a constant average rate \lambda (events per unit time) and independently.

  • Parameters: \lambda (average rate over the interval).

  • Range: 0, 1, 2, \dots (no upper bound).

  • PMF:

    P(X=k)=e−λλkk!P(X = k) = \frac{e^{-\lambda} \lambda^k}{k!}P(X=k)=k!e−λλk​
  • Expectation: \mathbb{E}[X] = \lambda

  • Variance: \text{Var}(X) = \lambda


New Discrete Random Variables 🎲

Geometric Random Variable

Story: Number of independent trials until the first success. Each trial has the same probability of success p.
Example: How many times do you need to flip a coin until you get heads? How many dates until you find "the one"?

Parameters:

  • p = probability of success on each trial ( 0 < p \leq 1 ).

Range: 1, 2, 3, \dots (cannot be zero because you need at least one trial to get a success).

PMF:

P(X=n)=(1−p)n−1pfor n=1,2,3,…P(X = n) = (1-p)^{n-1} p \quad \text{for } n = 1, 2, 3, \dotsP(X=n)=(1−p)n−1pfor n=1,2,3,…

Expectation: \mathbb{E}[X] = \frac{1}{p}

Variance: \text{Var}(X) = \frac{1-p}{p^2}

Example – Dating:
If the probability of meeting a life partner on any given date is p = 0.2, then the expected number of dates until finding "the one" is 1/0.2 = 5. The standard deviation is \sqrt{(1-0.2)/0.2^2} = \sqrt{20} \approx 4.47.


Negative Binomial Random Variable

Story: Number of independent trials until the r-th success. Each trial has the same probability of success p.
Example: How many times do you need to flip a coin until you get 3 heads? How many Bitcoin mining attempts until you mine 2 Bitcoins?

Parameters:

  • r = number of successes desired ( r = 1, 2, 3, \dots ).

  • p = probability of success on each trial.

Range: n = r, r+1, r+2, \dots (at least r trials are needed).

PMF:

P(X=n)=(n−1r−1)pr(1−p)n−rfor n≥rP(X = n) = \binom{n-1}{r-1} p^r (1-p)^{n-r} \quad \text{for } n \ge rP(X=n)=(r−1n−1​)pr(1−p)n−rfor n≥r

Expectation: \mathbb{E}[X] = \frac{r}{p}

Variance: \text{Var}(X) = r \cdot \frac{1-p}{p^2}

Relationship to Geometric:
A negative binomial with r successes is the sum of r independent geometric random variables (each counts trials until the next success). Therefore, expectation and variance are exactly r times those of a geometric with the same p.

Comparison with Binomial:

  • Binomial: Fixed number of trials n, random number of successes X.

  • Negative Binomial: Fixed number of successes r, random number of trials X.

Example – Bitcoin Mining:
Suppose the probability of mining a Bitcoin on any single attempt is p = (1/2)^G (requires G leading zeros in a hash). The number of attempts needed to mine 2 Bitcoins follows a negative binomial with r=2 and p = (1/2)^G.
The probability that fewer than 100 attempts are needed is:

P(X<100)=∑n=299(n−11)p2(1−p)n−2P(X < 100) = \sum_{n=2}^{99} \binom{n-1}{1} p^2 (1-p)^{n-2}P(X<100)=∑n=299​(1n−1​)p2(1−p)n−2

Alternatively, one can define a binomial: number of Bitcoins mined in 99 attempts, and ask for the probability of getting at least 2 successes.


More Random Variables: Learning New Ones

The key skill is not memorizing every distribution but being able to:

  1. Match a real-world problem to a narrative (story).

  2. Identify the parameters.

  3. Use the given PMF (discrete) or PDF (continuous) along with expectation and variance formulas.

Many reference sheets (e.g., the course reader's "Random Variable Reference") provide these formulas – you only need to know conceptually what each quantity means and which distribution fits.


Continuous Random Variables

Why Continuous?

Discrete random variables fail when outcomes are measured on a continuous scale (time, distance, exact position). For example:

  • What is the probability that you wait exactly 4.000... seconds for a bus? The probability is effectively zero because there are infinitely many precise values.

  • Instead, we ask for the probability that the wait time falls within an interval (e.g., between 3 and 5 minutes).

This requires a new representation: the probability density function (PDF).

Probability Density Function (PDF)

The PDF, denoted f(x), is the derivative of the cumulative probability. It is not a probability itself – it has units of probability per unit of x (e.g., probability per minute).

Key Properties:

  • f(x) \ge 0 for all x.

  • The total area under the curve equals 1:

    ∫−∞∞f(x) dx=1\int_{-\infty}^{\infty} f(x) \, dx = 1∫−∞∞​f(x)dx=1
  • The probability that X lies between a and b is the area under the PDF from a to b:

    P(a≤X≤b)=∫abf(x) dxP(a \le X \le b) = \int_a^b f(x) \, dxP(a≤X≤b)=∫ab​f(x)dx
  • f(x) can be greater than 1 if the range of x is small (since area, not height, must sum to 1).

Intuition:
A higher PDF value at a point means that values near that point are relatively more likely (the derivative of probability is larger). For instance, a PDF that peaks at 3:00 PM indicates the bus is more likely to arrive close to 3 PM.

Example – Semicircle PDF (from quantum physics):

f(x)=2πR2R2−x2for −R≤x≤R, else 0f(x) = \frac{2}{\pi R^2} \sqrt{R^2 - x^2} \quad \text{for } -R \le x \le R, \text{ else } 0f(x)=πR22​R2−x2​for −R≤x≤R, else 0

This PDF describes the distribution of eigenvalues in random matrices. To find P(X > 0), integrate from 0 to R or use symmetry – the area under the right half is exactly 1/2.


Cumulative Distribution Function (CDF)

The CDF, denoted F(x), gives the probability that a random variable is less than or equal to a specific value:

F(x)=P(X≤x)F(x) = P(X \le x)F(x)=P(X≤x)

For continuous random variables:

F(x)=∫−∞xf(t) dtF(x) = \int_{-\infty}^x f(t) \, dtF(x)=∫−∞x​f(t)dt

Using the CDF to Answer Probability Questions (No Integration Needed!):

  • P(X \le a) = F(a)

  • P(X > a) = 1 - F(a)

  • P(a \le X \le b) = F(b) - F(a)

The CDF is a function from \mathbb{R} \to [0,1], non-decreasing, with \lim_{x \to -\infty} F(x) = 0 and \lim_{x \to \infty} F(x) = 1.


Uniform Distribution

Story: A continuous random variable that is equally likely to take any value in the interval [\alpha, \beta].
Example: A bus that arrives uniformly between 0 and 30 minutes after a given time.

Parameters:

  • \alpha = minimum value

  • \beta = maximum value (\beta > \alpha)

PDF:

f(x)=1β−αfor α≤x≤β, and 0 otherwisef(x) = \frac{1}{\beta - \alpha} \quad \text{for } \alpha \le x \le \beta, \text{ and } 0 \text{ otherwise}f(x)=β−α1​for α≤x≤β, and 0 otherwise

CDF:

F(x)={0x<αx−αβ−αα≤x≤β1x>βF(x) = \begin{cases} 0 & x < \alpha \\ \frac{x - \alpha}{\beta - \alpha} & \alpha \le x \le \beta \\ 1 & x > \beta \end{cases}F(x)=⎩⎨⎧​0β−αx−α​1​x<αα≤x≤βx>β​

Expectation: \mathbb{E}[X] = \frac{\alpha + \beta}{2}

Variance: \text{Var}(X) = \frac{(\beta - \alpha)^2}{12}

Example – Waiting for the bus:
If arrival time is uniform on [0, 30] minutes and you arrive at t=15 minutes, what is the probability you wait less than 5 minutes?
You need the bus to arrive between 15 and 20 minutes.

P(15≤X≤20)=∫1520130 dx=530=16P(15 \le X \le 20) = \int_{15}^{20} \frac{1}{30} \, dx = \frac{5}{30} = \frac{1}{6}P(15≤X≤20)=∫1520​301​dx=305​=61​

Or using CDF: F(20) - F(15) = \frac{20}{30} - \frac{15}{30} = \frac{5}{30}.


Exponential Distribution

Story: The time until the next event in a Poisson process. It is the continuous counterpart of the Poisson distribution.
Examples: Time until the next earthquake, time until a web request arrives, time until the end of a cell phone contract.

Relationship with Poisson:

  • Poisson models number of events in a fixed interval (given rate \lambda per unit time).

  • Exponential models time between consecutive events (given the same rate \lambda).

Parameter:

  • Rate \lambda > 0 (average number of events per unit time).

PDF:

f(x)=λe−λxfor x≥0f(x) = \lambda e^{-\lambda x} \quad \text{for } x \ge 0f(x)=λe−λxfor x≥0

CDF:

F(x)=1−e−λxfor x≥0F(x) = 1 - e^{-\lambda x} \quad \text{for } x \ge 0F(x)=1−e−λxfor x≥0

Expectation: \mathbb{E}[X] = \frac{1}{\lambda}

Variance: \text{Var}(X) = \frac{1}{\lambda^2}

Memoryless Property (advanced): The exponential is the only continuous distribution that is memoryless – the remaining waiting time does not depend on how long you have already waited.

Example – Earthquakes at Stanford:
Major earthquakes in California occur at a rate of \lambda = 0.002 per year. Let Y be the number of years until the next major earthquake. Then Y \sim \text{Exponential}(\lambda = 0.002).

  • Probability of a major earthquake in the next 30 years:

    P(Y<30)=F(30)=1−e−0.002×30=1−e−0.06≈0.0582 (≈ 0.06)P(Y < 30) = F(30) = 1 - e^{-0.002 \times 30} = 1 - e^{-0.06} \approx 0.0582 \text{ (≈ 0.06)}P(Y<30)=F(30)=1−e−0.002×30=1−e−0.06≈0.0582 (≈ 0.06)
  • Probability of a major earthquake in the next 4 years:

    P(Y<4)=1−e−0.002×4=1−e−0.008≈0.008P(Y < 4) = 1 - e^{-0.002 \times 4} = 1 - e^{-0.008} \approx 0.008P(Y<4)=1−e−0.002×4=1−e−0.008≈0.008

These calculations use the CDF directly, avoiding integration.


Working with Continuous Random Variables: PDF vs. CDF

When solving problems, you have two options:

  1. Integrate the PDF – always works but requires calculus.

  2. Use the CDF – often simpler, especially when closed-form CDF is known.

Comparison for the Exponential Distr ibution:

Question

Using PDF

Using CDF

P(X < 2)

\int_0^2 \lambda e^{-\lambda x} dx

F(2) = 1 - e^{-2\lambda}

P(X > 1)

\int_1^\infty \lambda e^{-\lambda x} dx

1 - F(1) = e^{-\lambda}

P(1 < X < 2)

\int_1^2 \lambda e^{-\lambda x} dx

F(2) - F(1) = (1 - e^{-2\lambda}) - (1 - e^{-\lambda})

The CDF approach avoids integration once the CDF formula is known.


Summary of New Random Variables Introduced

Distribution

Type

Story

Parameters

Range

PMF/PDF

Expectation

Variance

Geometric

Discrete

Trials until 1st success

p

1,2,\dots

(1-p)^{n-1}p

1/p

(1-p)/p^2

Negative Binomial

Discrete

Trials until r-th success

r, p

r, r+1, \dots

\binom{n-1}{r-1}p^r(1-p)^{n-r}

r/p

r(1-p)/p^2

Uniform

Continuous

Equally likely on [\alpha,\beta]

\alpha, \beta

[\alpha,\beta]

1/(\beta-\alpha)

(\alpha+\beta)/2

(\beta-\alpha)^2/12

Exponential

Continuous

Time until next event (rate \lambda)

\lambda

x \ge 0

\lambda e^{-\lambda x}

1/\lambda

1/\lambda^2


Key Takeaways

  • Learning new random variables is about understanding the story – once you match a real scenario to a distribution, you automatically obtain its PMF/PDF, expectation, and variance from references (no derivation required for most applications).

  • Discrete vs. Continuous: Discrete random variables use PMFs (bar charts of probabilities); continuous random variables use PDFs (derivatives of probability) and require integration to find probabilities over intervals.

  • CDFs simplify continuous probability calculations: F(x) = P(X \le x); use subtraction to find probabilities of ranges.

  • The exponential distribution is the continuous best friend of the Poisson – it measures time until an event, while the Poisson measures counts in a fixed interval.

  • The uniform distribution models complete randomness over an interval with equal likelihood everywhere.

  • Mastering these concepts enables you to approach complex problems (server queues, earthquake risk, random number generation) with confidence and efficiency.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent