# combinationsWithRep() Function & Examples

Use the combinationsWithRep() probability function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## combinationsWithRep

#### combinationsWithRep(n, k)

Try it yourself:

```calculio
combinationsWithRep(7, 5)
```

[combinations](https://calcul.io/function/combinations/index.md)

[permutations](https://calcul.io/function/permutations/index.md)

[factorial](https://calcul.io/function/factorial/index.md)

---

## combinationsWithRep(): choose with repetition

**combinationsWithRep(n, k)** counts unordered selections of k items from n types when a type may appear more than once. Selecting three scoops from five flavours, where repeats are allowed, has `combinationsWithRep(5, 3)` possible outcomes.

## Stars and bars

The formula is `combinations(n + k − 1, k)`. It is often called “stars and bars”: k selected items are stars, and separators allocate them among n categories. This is useful for inventory allocations, integer solutions, and multisets.

## Compare related counts

Use [combinations()](https://calcul.io/function/combinations/index.md) when repeated choices are forbidden. Use [permutations()](https://calcul.io/function/permutations/index.md) if order matters. [factorial()](https://calcul.io/function/factorial/index.md) gives its factorial expansion. See [catalan()](https://calcul.io/function/catalan/index.md) for another family of discrete counts.

## Input requirements

Use non-negative integer n and k. n represents available types; k represents selections. Be explicit about whether an empty selection is meaningful in your application.

[All functions](https://calcul.io/functions/index.md)
