ForHosting KIT · Math

Discrete uniform mean and variance calculator

A fair die from 1 to 6 has 6 equally likely outcomes, a mean of 3.5 and a variance of 35/12. Enter the lowest and highest whole number, both included, and get the mean, the variance and how many results are possible. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
A
1
B
6
You get
Mean
3.5
Variance
2.9166666667
Support size
6

This discrete uniform mean and variance calculator describes a random integer chosen with equal probability from an inclusive interval. Enter the lower bound a and upper bound b, and it returns the distribution mean, variance, and number of possible integer outcomes. It is useful for fair dice-like models, randomized integer selections, simulation checks, and probability exercises. The calculation uses exact closed-form formulas and rejects an interval whose upper bound is below its lower bound.

Define the inclusive integer support correctly

A discrete uniform distribution assigns the same probability to every integer in a finite interval. The support size is therefore b − a + 1, not b − a. That extra one is important: forgetting it changes both the probability of each result and the variance.

Bounds may be negative, positive, or zero, provided both are safe integers and b is not below a. A one-point interval is also valid. If a and b are both 4, the only possible outcome is 4, so its mean is 4 and its variance is zero.

This calculator is specifically for equally likely consecutive integers. It does not model a continuous uniform variable, skipped integer values, unequal weights, or categorical outcomes. Those cases require a different distribution or a direct weighted calculation.

Understand the mean and variance formulas

The mean does not have to be an integer. A fair die from 1 to 6 has mean 3.5, which is the long-run average rather than a result that must appear on a single trial. If n = b − a + 1 is the support size, the variance is (n² − 1) / 12.

Variance measures average squared distance from the mean, so it is expressed in squared units and cannot be negative. Notice that shifting both bounds by the same amount changes the mean but not the variance: the width and spacing remain identical. Widening the interval increases variance because results can lie farther from the center.

Use the result in analysis and validation

In a simulation, compare the observed sample average and sample variance with these theoretical values to check whether a supposedly uniform integer generator behaves plausibly. Small samples will naturally differ, so the formulas provide targets rather than a promise for every run. In game analysis, use the mean as the expected numerical outcome and the variance as a measure of spread, but remember that expected outcome is not automatically expected profit; payouts and costs must be transformed before averaging.

A random-integer function documented as inclusive at both ends should have exactly b − a + 1 outcomes. Invalid ordering is rejected instead of silently swapping bounds because swapping can hide a data-entry or integration error.

Check a random integer simulation

Compute the theoretical mean and variance to compare with summary statistics from uniformly generated integer samples.

Analyze a fair numbered game

Describe the center and spread of equally likely consecutive scores, spins, cards, or die-like outcomes.

What happens when a equals b?

The distribution has one possible outcome. Its mean equals that bound and its variance is zero.

Why can the mean be a non-integer?

The mean is a long-run average. It can lie halfway between two supported integers even though no individual draw has that value.

Does this calculate a continuous uniform distribution?

No. It is for equally likely consecutive integers. A continuous uniform distribution uses a different variance formula.

Why are there b − a + 1 possible outcomes?

Because both ends are included: from 1 to 6 there are six results, not five. Forgetting that extra one changes the probability of each result and also the variance, which depends on the number of outcomes.

Does shifting the interval change the variance?

No. Moving both bounds by the same amount changes the mean but not the variance, because the width and the spacing stay the same. Only a wider interval raises the variance, since results can land farther from the center.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/stat/discrete-uniform-mean-variance

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/stat/discrete-uniform-mean-variance \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"a":1,"b":6}'
{
  "a": 1,
  "b": 6
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "stat.discrete_uniform_mean_variance",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Define the inclusive integer support correctly

Here, a is the smallest possible result and b is the largest, and both endpoints are included. For example, a = 1 and b = 6 describe an ordinary fair six-sided die because the support is 1, 2, 3, 4, 5, 6.

Understand the mean and variance formulas

For consecutive integers from a through b with equal probability, symmetry places the mean halfway between the endpoints: mean = (a + b) / 2. The implementation evaluates equivalent factored arithmetic for the variance and splits the endpoint sum when finding the mean, helping avoid an unnecessary intermediate overflow. Results follow deterministic JavaScript number arithmetic, and the inputs are restricted to safe integers so that each stated endpoint and support count has an unambiguous numeric representation.

Use the result in analysis and validation

The returned object contains mean, variance, and support_size, making it suitable for a worksheet, an API pipeline, or an automated test. The support size is useful for confirming that endpoint conventions agree across systems. If another tool treats the upper endpoint as exclusive, its distribution is different. For automated access, each request costs $0.002; the same deterministic calculation can also run in the browser without sending the bounds elsewhere.

Verify endpoint conventions

Confirm the expected number of outcomes when an API or program claims to sample inclusively from a through b.

Are a and b included in the distribution?

Yes. Every integer from a through b, including both endpoints, has equal probability.

What if b is below a?

The request returns an invalid_input error because the upper bound cannot be below the lower bound.

What does an API request cost?

An API request costs $0.002. The browser calculation is also available without an API call.

Read the full KIT documentation →