Token counts, latencies, and right-or-wrong scores are all numbers that change from run to run. This lesson gives you the two summaries that matter for any such number, and the rules for what happens when you scale, add, or average them.
In Lesson 2 you summarized a pile of numbers you already had. In Lessons 3 and 4 you assigned probabilities to outcomes you hadn't seen yet. Now you join the two: attach a number to each uncertain outcome, and ask what that number does on average and how much it wobbles. Once you can do that, questions like "what does a request cost us?", "how long does the whole agent take?", and "how noisy is this eval score?" become short calculations instead of guesses.
An outcome by itself ("the model produced this particular response") isn't a number. A random variable is a rule that turns each outcome into one. You pick the rule based on what you want to know about the response:
Whatever text the model writes, X counts its tokens. Takes whole-number values. A discrete variable.
The Bernoulli variable from Lesson 4. One response in, a 0 or 1 out.
Can be any value on a continuous scale, so it is a continuous variable. Lesson 13 handles those; this lesson stays with discrete ones.
The word "random" only means the value isn't known until the outcome happens. Before the request runs, X is uncertain. After it runs, you have one observed value, an ordinary number from Lesson 2. The distribution is the rule that tells you, in advance, how likely each value is.
For a discrete variable, the probability mass function (PMF) lists each possible value and its probability. The probabilities must sum to 1, the same requirement as in Lesson 3. Say a team logs a month of traffic on a support assistant and groups response lengths into four sizes:
| Response size | X (tokens) | P(X = x) | P(X ≤ x) |
|---|---|---|---|
| Short answer | 100 | 0.4 | 0.4 |
| Normal answer | 200 | 0.3 | 0.7 |
| Long answer | 400 | 0.2 | 0.9 |
| Very long answer | 800 | 0.1 | 1.0 |
The last column is the cumulative distribution function (CDF): F(x) = P(X ≤ x), the running total of the PMF. It answers "what fraction of responses are at most this long?" For example, F(400) = 0.4 + 0.3 + 0.2 = 0.9, so 90% of responses are 400 tokens or fewer. Flip it around and you get tail questions for free: P(X > 400) = 1 − F(400) = 0.1, the share of responses that run very long. Percentiles from Lesson 2, like p90, are just the CDF read backward.
The expected value E[X] is each possible value multiplied by its probability, then summed. It is the mean of the distribution, the number the long-run average of observed values settles toward.
Note that 260 is not one of the four possible sizes. No single response is 260 tokens long. Expected value is a balance point, not a prediction of the next draw. The chart below shows it: the long right tail (the 800-token bar, only 10% of traffic) pulls the balance point well above the most common size.
PMF of response length. Dashed line: the mean, 260 tokens. Shaded band: one standard deviation (about 211) either side of the mean, from the calculation in section 4.
A team prices a request in micro-dollars (µ$): a fixed 400 µ$ for processing the prompt, plus 2 µ$ for every output token. These prices are illustrative. The cost of a request is itself a random variable, Y = 2X + 400. To find E[Y] you could compute the cost of each size and weight it:
The linearity rule in section 5 gets the same answer without the table: 2(260) + 400 = 920. At 1,000,000 requests a month, the expected bill is 920,000,000 µ$, which is $920. Expected value is how you turn a per-request distribution into a budget.
Lesson 2 defined variance as the average squared distance from the mean, computed over a dataset you hold. The definition for a random variable is the same idea with probabilities as the weights:
For the response-length variable, with μ = 260:
The 800-token bar carries 29,160 of the 44,400, two thirds of the total, from just 10% of traffic. The squaring from Lesson 2 does what it always does: rare large deviations dominate. A handy equivalent form is Var(X) = E[X²] − (E[X])². Check: E[X²] = 10,000(0.4) + 40,000(0.3) + 160,000(0.2) + 640,000(0.1) = 4,000 + 12,000 + 32,000 + 64,000 = 112,000, and 112,000 − 260² = 112,000 − 67,600 = 44,400. Same result.
You already used this rule above. For any constants a and b, and any random variables X and Y:
The cost example is the first rule: E[2X + 400] = 2(260) + 400 = 920, matching the table calculation. Scaling the variable scales its mean; adding a constant shifts it.
The second rule is the surprising one: it holds even when X and Y are dependent. No independence assumption is needed. Suppose an agent writes a reply, then a follow-up whose length always matches the first (an extreme dependence: knowing X tells you Y exactly). The total is X + X:
Direct check: the total is 200, 400, 800, or 1,600 with probabilities 0.4, 0.3, 0.2, 0.1, so E = 80 + 120 + 160 + 160 = 520. It works because expectation is just a weighted sum, and sums of weighted sums rearrange freely. This is why you can budget a multi-step workflow by adding up the expected cost of each step without first untangling how the steps influence each other.
Variance does not follow the same rules as the mean:
Two things happen. Adding a constant b slides every value by the same amount, so the spread doesn't change: b drops out. Multiplying by a stretches every distance from the mean by a, and variance squares distances, so it grows by a². Apply it to the cost variable Y = 2X + 400:
The standard deviation scales by |a| and ignores b. The fixed prompt cost of 400 µ$ raises the average bill but adds nothing to its unpredictability. Only the part that varies, the output tokens, contributes spread.
Now the sum of different variables. If X and Y are independent (the idea from Lesson 3: knowing one tells you nothing about the other):
Take a three-step agent: retrieve documents, call the LLM, then run a tool. Suppose a team measures each step and finds the following, treating the three as independent:
| Step | Mean (ms) | SD (ms) | Variance (ms²) |
|---|---|---|---|
| Retrieval | 120 | 30 | 900 |
| LLM call | 800 | 200 | 40,000 |
| Tool call | 80 | 40 | 1,600 |
Add the means, add the variances, then take the square root. The total SD of 206 ms is barely above the LLM step's own 200 ms: the LLM call accounts for 40,000 of the 42,500 units of variance. If you wanted to make the whole pipeline more predictable, tuning retrieval from 30 ms SD to 10 ms SD would change the total variance from 42,500 to 41,700. Almost nothing. The variance table tells you where effort pays off.
These rules let you re-derive the mean and variance from Lesson 11's binomial without any counting. One eval question scored 1 if the model is right and 0 otherwise is a Bernoulli variable C with success probability p:
Score n independent questions and count the correct ones: the count is C₁ + C₂ + … + Cₙ. Linearity gives the mean by adding n copies of p, and independence lets the variances add:
So a model that is truly right 80% of the time scores 40 out of 50 on average, but a typical run lands within about 3 questions of that on either side. The formulas are the ones from Lesson 11; this is where they come from.
Now divide a sum by n to get an average. The average of n independent copies of a variable with mean μ and variance σ² is (1/n) times the sum, so the rules above give:
The average keeps the same mean but its spread shrinks with the square root of n. Using the LLM step from the pipeline (SD 200 ms), averaging more runs of the same call gives:
| Runs averaged (n) | SD of the average |
|---|---|
| 1 | 200 / √1 = 200 ms |
| 4 | 200 / 2 = 100 ms |
| 25 | 200 / 5 = 40 ms |
| 100 | 200 / 10 = 20 ms |
The same applies to eval scores. A single question has SD √(0.8 × 0.2) = 0.4 around its mean of 0.8. Averaged over 100 independent questions, the accuracy has SD 0.4 / √100 = 0.04. That is the 4 percentage points of noise you should expect between two runs of the same model on two fresh 100-question sets. Over 400 questions it drops to 0.4 / 20 = 0.02. Quadrupling the data only halves the noise, which is why chasing small accuracy differences gets expensive fast.
Linearity means cost and token budgets for multi-step workflows are sums of per-step expectations, no matter how the steps interact. But a budget built on the mean alone hides the tail: in the example, 10% of requests cost 2,000 µ$, more than double the 920 µ$ average. Check the CDF as well as the mean.
Because independent variances add, you can decompose a pipeline's unpredictability step by step, as in the three-step table. Work on the step with the largest variance, and be suspicious of the independence assumption when steps share infrastructure.
An accuracy from n questions has SD around √(p(1 − p) / n). If two models differ by less than a couple of those SDs, you may be looking at noise. Lesson 9 turns this into a proper comparison; here you have the quantity it is built on.
1. A response-length variable has P(100 tokens) = 0.4, P(200) = 0.3, P(400) = 0.2, P(800) = 0.1. What is the CDF value F(400)?
2. For that distribution E[X] = 260 tokens. A new pricing charges 3 µ$ per token plus a fixed 50 µ$, so cost = 3X + 50. What is the expected cost?
3. Var(X) = 44,400. What is Var(3X + 50)?
4. A pipeline has three independent steps with SDs of 30 ms, 200 ms, and 40 ms. What is the SD of the total time?
5. One eval question has SD 0.4 (a 0/1 score with p = 0.8). If you average the scores of 100 independent questions, what is the SD of the average?
Everything here used discrete variables: a short list of values, each with its own probability. Latency, a model's confidence score, and a gradient's size can take any value in a range, and there the "probability of exactly this value" is effectively zero. Lesson 13 replaces the PMF with a density and the sums with areas. Expected value and variance carry over unchanged in meaning, and so do all the rules above.