Combinations with repetition
Count selections where each type can repeat and order does not matter: 3 picks from 5 types give 35, which is C(7, 3), the same stars-and-bars count used for sharing identical items among categories. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Number of distinct types
- 5
- Resistance (Ω)
- 3
- Quantity
- 35
- N plus r minus 1
- 7
- Max n
- 500
- Max r
- 500
This combinations-with-repetition calculator returns how many distinct multisets of size r you can form from n types when each type may be chosen more than once and order does not matter. Small checks you may already know include five types and three picks yielding thirty-five, three types and two picks yielding six, and any valid n with zero picks yielding one for the empty selection. The engine uses deterministic BigInt binomial arithmetic only: no network calls, no sampling, and no date-dependent shortcuts.
What combinations with repetition mean and what you get
Combinations with repetition count unordered selections where the same type can appear more than once. That is different from ordinary combinations C(n, r), which forbid reuse, and different from permutations, which care about order. Formally the count is C(n + r − 1, r) for positive n and non-negative r; equivalently C(n + r − 1, n − 1).
Stars and bars interpret the same number as the number of ways to place r indistinguishable items into n distinguishable bins, which is why the tool is useful for both pure combinatorics and applied counting problems such as distributing identical units across categories. This calculator returns the requested n and r, the exact count as a decimal string, the intermediate upper index n plus r minus one, a short formula string such as C(7, 3), and the published maxima so clients can validate before they send a batch.
Where multiset combinations fit in study, code, and modeling
Students meet combinations with repetition when a textbook contrasts them with ordinary combinations, when a stars-and-bars exercise asks for non-negative solutions to a linear Diophantine equation, or when they need a clean count of multisets of a fixed size. Teachers can pre-generate answer keys for modest n and r without trusting opaque calculator apps that round large integers or silently switch to scientific notation.
Developers call the same contract from scripts to seed deterministic test vectors, to size inventory or coupon-collector style models that allow repeated categories, or to satisfy programming-challenge statements that demand the exact multichoose value rather than a log-space approximation. Contest practice often needs a fast, offline source of multiset-combination ranks so solutions can be checked without downloading OEIS tables under time pressure.
Product and operations analysts use the count when estimating how many distinct order baskets of size r can arise from n SKUs if quantity per SKU is unbounded and order of listing does not matter.
What you can do with it
Homework and stars-and-bars checks
Look up exact C(n+r−1, r) values for textbook multiset-combination exercises and non-negative integer solution counts.
Inventory and basket sizing
Count distinct unordered selections of r items from n types when repetition is allowed, for product or modeling scenarios.
FAQ
What does the combinations-with-repetition calculator cost?
It is free in your browser on this page.
How is the count defined?
The number of ways to choose r items from n types with repetition allowed and order irrelevant is C(n+r−1, r).
Is this the same as ordinary combinations C(n, r)?
No. Ordinary combinations forbid repeating a type. This tool allows repetition (multiset combinations / multichoose).
What are the largest numbers of types and picks I can enter?
Both the number of types and the number of picks can go up to 500. That limit keeps every answer exact and quick, even though these counts grow very fast.
Why do I get 1 when I choose zero items?
Choosing nothing counts as exactly one selection: the empty one. Any valid number of types with zero picks returns 1, following the usual convention in counting problems.
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/combo/combinations-with-repetition \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":5,"r":3}'const res = await fetch("https://api.kit.forhosting.com/combo/combinations-with-repetition", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 5,
"r": 3
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/combo/combinations-with-repetition",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 5,
"r": 3
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/combo/combinations-with-repetition", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":5,"r":3}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":5,"r":3}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/combo/combinations-with-repetition", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 5,
"r": 3
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "combo.combinations_with_repetition",
"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_n | 500 |
max_r | 500 |
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
The classic closed form is n plus r minus one choose r, written C(n+r−1, r), also known as multichoose, multiset combinations, or the stars-and-bars count of non-negative integer solutions to x_1 + … + x_n = r.
What combinations with repetition mean and what the response contains
There is no approximate floating-point path presented as truth and no random sampling of subsets: the engine either builds the exact binomial product inside the supported range or rejects the input with invalid_input. Rejected cases include missing n or r, non-integers, fractions, scientific notation, values above the documented ceilings, n below one, and any negative r.
How n and r are read and how BigInt keeps every digit exact
Optional leading plus signs are allowed; embedded spaces, hex prefixes, negative signs where forbidden, and exponential notation are rejected with a clear message so a bad cell does not become a wrong count. Zero for r is valid and returns one, matching the empty-product and empty-selection conventions used in discrete mathematics. Computation uses the multiplicative BigInt formula for C(a, b): multiply successive factors (a − i) / (i + 1) for i from zero through the smaller of b and a − b, so intermediate values stay exact without building full factorials that would waste time and memory. The preferred fields are n for the number of types and r for how many items to select, but aliases types and kinds for n and k and count for r are accepted so spreadsheets, query strings, and typed forms can reuse the same contract. The engine enforces hard maxima of five hundred on both n and r, which keeps memory and latency inside a predictable budget on the free browser path and on the edge Worker even though binomial coefficients grow quickly. Every intermediate is a BigInt and the final count is serialized with toString so JSON never loses digits the way IEEE doubles would after the fifty-third bit. Pair the free browser run on this page with the priced API when you need the identical mathematical result inside an automated pipeline without re-implementing stars and bars yourself.
Where multiset combinations fit in study, code, and modeling
On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split — free interactive exploration and a priced, identical API — matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the mathematical result. Pair it with factorial or binomial tools when you need related coefficients, with permutation counters when order matters, and with other math endpoints when you are building a small lab of free, deterministic combinatorics helpers.
Integration use cases
Deterministic test fixtures
Generate reproducible multichoose decimal strings for unit tests, property checks, and CI assertions without hand-maintaining tables.
Technical questions
What happens if n is below 1 or r is negative?
Both cases are rejected with invalid_input. n must be at least 1 and r must be non-negative.
Why is the result a string instead of a number?
Binomial coefficients can exceed JavaScript safe integers. Returning a decimal string keeps every digit exact in JSON and in the browser.