Random Variable (original) (raw)

Last Updated : 11 May, 2026

A random variable is a key concept in statistics that connects theoretical probability with real-world data. It is a function that assigns a real number to each outcome in the sample space of a random experiment.

**For example: When you roll a die, the outcome is one of the six faces. A random variable can assign a number (like 1 to 6) to each of these outcomes, allowing us to analyze the results using statistical methods.

random_variable

There are two possible outcomes, modeled as random variables

We define a random variable as a function that maps from the sample space of an experiment to the real numbers. Mathematically, a Random Variable is expressed as,

**X: S →R

**Where:

Random variables are generally represented by capital letters like X and Y.

**Random Variable Examples

**Example 1: If two unbiased coins are tossed, then find the random variable associated with that event.

**Solution:

Suppose Two (unbiased) coins are tossed
X = number of heads. [X is a random variable or function]

Here, the sample space S = {HH, HT, TH, TT}

Suppose a random variable X takes m different values, X = {x1, x2, x3,..., xm}, with corresponding probabilities **P(X = x i ) = p i, where 1 ≤ i ≤ m.
The probabilities must satisfy the following conditions :

**Example 2: Suppose a die is thrown (X = outcome of the dice) and the sample space S = {1, 2, 3, 4, 5, 6}.

**Solution:

The output of the function will be:

This also satisfies the condition ∑6i=1 P(X = i) = 1, since:
P(X = 1) + P(X = 1) + P(X = 2) + P(X = 3) + P(X = 4) + P(X = 5) + P(X = 6) = 6 × 1/6 = 1

Variate

A variate is a general term often used interchangeably with a random variable, particularly in contexts where the random variable is not yet fully specified by a particular probabilistic experiment.

Types of Random Variables

Random variables are of two types, that are as follows:

Types-of-random_variable

Types Of Random Variable

**Discrete Random Variable

A Discrete Random Variable takes on a finite or countably infinite number of values. The probability function associated with a discrete random variable is called as Probability Mass Function.

PMF(Probability Mass Function)

If X is a discrete random variable and the PMF of X is P(xi), then

**Discrete Random Variables Example

**Example: **Let S = {0, 1, 2}

xi 0 1 2
Pi(X = xi) P1 0.3 0.5

**Find the value of P (X = 0)

**Solution:

We know that the sum of all probabilities is equal to 1. And P (X = 0) be P1
P1 + 0.3 + 0.5 = 1
P1 = 0.2

Then, P (X = 0) is 0.2

**Continuous Random Variable

A Continuous Random Variable takes on an infinite number of values. The probability function associated with it is said to be PDF (Probability Density Function).

**PDF (Probability Density Function)

If X is a continuous random variable. P (x < X < x + dx) = f(x)dx then,

Then P (X) is said to be a PDF of the distribution.

**Example: Find the value of P (1 < X < 2) f(x) = kx 3 ; 0 ≤ x ≤ 3 = 0. Otherwise, f(x) is a density function.

**Solution:

If a function f is said to be a density function, then the sum of all probabilities is equal to 1.

Since it is a continuous random variable Integral value is 1 overall sample space s.

∫ f(x) dx = 1
∫ kx3 dx = 1
K[x4]/4 = 1

Given interval, 0 ≤ x ≤ 3 = 0

K[34 – 04]/4 = 1
K(81/4) = 1
K = 4/81

Thus,

P (1 < X < 2) = k × [X4]/4
P = 4/81 × [16-1]/4
P = 15/81

Random Variable Formulas

There are two main random variable formulas,

1. Mean of a Random Variable

For any random variable X where P is its respective probability, we define its mean as,

**Mean(μ) = ∑ X.P

**Where,

2. Variance of a Random Variable

The variance of a random variable tells us how the random variable is spread about the mean value of the random variable. The variance of the Random Variable is calculated using the formula,

**Var(x) = σ 2 = E(X 2 ) - {E(X)} 2

**Where,

Random Variable Functions

For any random variable X if it assume the values x1, x2,...xn where the probability corresponding to each random variable is P(x1), P(x2),...P(xn), then the expected value of the variable is,

Expectation of X, E(x) = ∑ x.P(x)

Now, for any new random variable Y in which the random variable X is its input, i.e., Y = f(X), then the cumulative distribution function of Y is,

**F y (Y) = P(g(X) ≤ y)

Probability Distribution and Random Variable

For a random variable, its probability distribution is calculated using three methods,

The probability of a random variable X that takes values x is defined using a probability function of X that is denoted by f (x) = f (X = x).

Random Variables in Computer Science

Random variables are important in computer science for dealing with uncertainty and chance.

Solved Questions

**Question 1: Find the mean value of the continuous random variable with probability density function,f(x) = \frac{3x^2}{26}, 1 ≤ x ≤ 3.
**Solution:

Given,
f(x) = \frac{3x^2}{26} , 1 ≤ x ≤ 3

The mean (expected value) of a continuous random variable is: E(X)=\int_{1}^{3}x\cdot f(x)\,dx

Substitute the value of f(x): E(X)=\int_{1}^{3}x\cdot \frac{3x^2}{26}\,dx

E(X)=\frac{3}{26}\int_{1}^{3}x^3\,dx

Using integration,
E(X)=\frac{3}{26}\left[\frac{x^4}{4}\right]_{1}^{3}
E(X)=\frac{3}{26}\times \frac{3^4-1^4}{4}
E(X)=\frac{3}{26}\times \frac{81-1}{4}
E(X)=\frac{3}{26}\times \frac{80}{4}
E(X)=\frac{3}{26}\times 20
E(X)=\frac{60}{26}

Therefore, E(X)=\frac{30}{13}

**Question 2: Find the mean value for the continuous random variable, f(x) = ex, 1 ≤ x ≤ 3
**Solution:

Given,
f(x) = ex
1 ≤ x ≤ 3

E(x) = \int_{1}^{3} x \cdot f(x) \, dx
E(x) = \int_{1}^{3} x \cdot e^x \, dx
E(x) = [x.ex - ex]31
E(x) = [ex(x - 1)]31
E(x) = e3(2) - e(0)

**Question 3: Given the discrete random variable X with the following probability distribution:

**X **1 **2 **3 **4
**P(X) **0.1 **0.2 **0.4 **0.3

Find the mean value (or expected value) of the random variable X.
**Solution:

To find the mean value (expected value) of a discrete random variable X, we use the formula:
Using the relation: E(X) = μX = x1P(x1) + x2P(x2) + ... + xnP(xn)
E(X) = ∑i Xi · P(Xi)

**The expected value E(X), or mean μ X of a discrete random variable X
E(X) = μX = ∑ [ x__i_ * P(x__i_) ]
E(X) = 1 * 0.1 + 2 * 0.2 + 3 * 0.4 + 4 * 0.3
E(X) = 0.100 + 0.400 + 1.200 + 1.200 = 2.900
**E(X) = 2.900

**Question 4: Given the discrete random variable X with the following probability distribution:
Suppose a discrete random variable X represents the number of defective items in a sample of 10 items from a batch of 100 items. The possible values of X are 0, 3, 5, and 7 defective items, with the following probability distribution:

X 0 3 5 7
P(X) 0.2 0.5 0.2 0.1

Find the mean value (or expected value) of the random variable X.
**Solution:

The formula for the **mean (or **expected value) of a discrete random variable X is:
E(X) = ∑i Xi ⋅ P(Xi)

**The expected value E(X), or mean μ X of a discrete random variable X

E(X) = μX = ∑ [ x__i_ * P(x__i_) ]
E(X) = 0 * 0.2 + 3 * 0.5 + 5 * 0.2 + 7 * 0.1
E(X) = 0.000 + 1.500 + 1.000 + 0.700 = 3.200
**E(X) = 3.200

Practice Problems

**Question 1: Find the mean value for the continuous random variable, f(x) = x3, 1 ≤ x ≤ 5
**Question 2: Find the mean value for the continuous random variable, f(x) = x, 1 ≤ x ≤ 4.
**Question 3: Given the discrete random variable X with the following probability distribution:

**X **1 **2 **3 **4
**P(X) **0.2 **0.3 **0.4 **0.1

Find the mean value (or expected value) of the random variable X.

**Question 4: Given the discrete random variable X with the following probability distribution:

**X **0 **1 **3 **5
**P(X) **0.3 **0.3 **0.3 **0.1

Find the mean value (or expected value) of the random variable X.

**Answer:-

  1. 624.8.
  2. 2.4.
  3. 1.7.