Geometric distribution calculator
If each try succeeds with probability 0.25, the first success lands exactly on the third try with probability 0.140625, and you should expect 4 tries on average. Enter the success chance and the trial number to get both. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Power (W)
- 0.25
- K
- 3
- Q
- 0.75
- Probability
- 0.140625
- Probability number
- 0.140625
- Probability percent
- 14.0625
The geometric distribution answers a simple repeated-trial question: if every attempt succeeds with the same probability p, what is the chance that the first success lands exactly on trial k? Students meet this model in textbooks; analysts meet it in retry loops, sales funnels, and quality-control spot checks. This capability evaluates the classic trials-until-first-success form of the geometric law: P(X equals k) equals (1 minus p) to the power (k minus 1), times p, for positive integers k. It also returns the expectation E[X] equals one over p, the variance, and the cumulative probability that the first success has already happened by trial k. Inputs are validated strictly: p must lie in the open-closed interval (0, 1], and k must be a whole positive integer within published limits.
What the geometric model covers and how probability is defined
Imagine independent Bernoulli trials that each succeed with fixed probability p and fail with probability q equals one minus p. Keep going until the first success appears. The random variable X is the trial number of that first success, so the support is the positive integers one, two, three, and so on.
Exactly one path produces a first success on trial k: fail on the first k minus one trials, then succeed on trial k. Because trials are independent, that path has probability q to the power (k minus one) times p. That expression is the probability mass function returned by this calculator.
The expectation follows from the standard series for the geometric law: on average you need one over p trials before the first success, so a process with p equals one fourth expects four attempts. Variance is q over p squared, which grows when successes are rare.
The cumulative distribution function F of k equals one minus q to the power k, which is the probability that the first success has already occurred on or before trial k—useful when a policy says “give up after ten tries” and you want the chance you already succeeded by then. This landing deliberately uses the trials-until-success convention (support starts at one), not the failures-before-success convention (support starts at zero). Both appear in literature; they shift k by one and change the expectation from one over p to q over p.
Coin-flip style demos with p equals one half and small k are easy to check by hand: for k equals three you get (one half) squared times one half equals one eighth. Edge cases are handled explicitly: when p equals one, the first success is certain on trial one and impossible later; when p approaches zero the mass spreads over large k and the expectation grows without bound—so p equals zero is rejected rather than returning a silent infinity.
What you can do with it
Retry and polling design
Given an estimated per-attempt success rate, compute the chance the first success lands on attempt k and the mean number of tries before a service answers.
Quality control and inspection sampling
Model independent item inspections until the first defect (or first pass) and report both the trial-k probability and the expected inspection count.
FAQ
Which geometric convention does this use?
Trials until first success: X is the trial number of the first success, so k starts at 1 and P(X=k)=(1-p)^(k-1)*p with E[X]=1/p.
What values of p are allowed?
p must be in (0, 1]: greater than zero and at most one.
Is the result approximate or exact?
The formulas are exact; floating-point evaluation uses log-space for large k so the PMF remains stable. No random sampling is used.
Is the geometric distribution calculator free?
The browser tool is free and runs locally.
What is the chance of succeeding by trial k at the latest?
That is the cumulative value: one minus the failure chance raised to the power k. With a success chance of 0.25 and the third try it is 0.578125, useful when a rule says to give up after a fixed number of attempts.
Related tools
For developers — API access
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.
API endpoint
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.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/prob/geometric-distribution \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"p":0.25,"k":3}'const res = await fetch("https://api.kit.forhosting.com/prob/geometric-distribution", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"p": 0.25,
"k": 3
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/prob/geometric-distribution",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"p": 0.25,
"k": 3
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/prob/geometric-distribution", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"p":0.25,"k":3}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"p":0.25,"k":3}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/prob/geometric-distribution", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"p": 0.25,
"k": 3
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "prob.geometric_distribution",
"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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_k | 1000000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Values of p outside zero to one are rejected with invalid_input so homework answers and production retries stay honest.
What the geometric model covers and how probability is defined
If your textbook writes P of Y equals k as q to the k times p for k starting at zero, translate by setting this tool’s k to Y plus one, or compare only the shared p and the PMF formula printed in the JSON.
How to call the API and read the JSON response
Two formula strings document the convention so downstream UIs can show the same definition humans searched for. Classic check: p equals zero point two five and k equals three yields probability zero point one four zero six two five, expected trials four, and variance twelve. Another check: p equals one and k equals one yields probability one and expected trials one; the same p with k equals two yields probability zero. Send a JSON body with two required fields. Field p is the success probability on each trial; aliases probability, success_p, and prob are accepted. It must be a finite number strictly greater than zero and at most one. Field k is the trial index of the first success you care about; aliases trial, n, and trials map to the same meaning. k must be a whole integer from one through one million. A successful response echoes the normalized p and k, the failure probability q, and the PMF as both a trimmed decimal string (probability) and an IEEE double (probability_number) plus a percentage string. It also returns expected_trials as one over p, variance as q over p squared, and the CDF at k as cdf and cdf_number. Pricing is a flat $0.002 per successful request with unit item and zero marginal unit price. Prefer probability (string) when you need stable display digits; use probability_number when you will chain further floating-point math in a client script.
Practical tips, limits, and how this differs from related tools
Do not confuse this landing with binomial tools or combination counters elsewhere in the kit: the binomial law counts how many successes occur in a fixed number of trials, while the geometric law stops at the first success and treats the trial index as random. Dice-sum probability landings answer a different search intent—sums of polyhedral faces—not repeated Bernoulli waits. If you need the failures-before-success parameterization, convert: number of failures before first success is X minus one, with expectation q over p; this calculator keeps the trial-number form because that matches the phrase “first success on trial k” in search queries. Stay inside k at most one million so log-space evaluation of the PMF stays cheap in both Worker and browser. For classroom demos, prefer small textbook pairs—p equals one half with k equals one through five, or p equals one tenth with k equals ten—so students can expand (one minus p) to the power (k minus one) by hand and match the API line by line. When modeling software retries, map “attempt number” to k and the observed success rate to p; expected_trials then tells you the mean number of attempts before a healthy endpoint answers, and the CDF tells you how often you finish within a budgeted attempt limit. Failed validation never spends prepaid balance, so exploratory scripts can probe edges cheaply. Prefer the printed formula fields when documenting homework solutions, and prefer expected_trials over ad-hoc spreadsheet inverses of p so every teammate shares the same definition of the mean wait.
Integration use cases
Homework and probability teaching labs
Assign geometric PMF and expectation exercises and let students check P(X=k) and E[X]=1/p against a deterministic API or free browser result.
Technical questions
What does expected_trials mean?
It is E[X] = 1/p, the mean number of independent trials needed until the first success under this geometric model.