There is a mathematical formula which will produce the number of **combinations**, or **permutations**, from a number of selections.

Note that combinations and permutations have different mathematical meanings. Permutations have a specific order: i.e. 123 is different to 321. However, for combinations, the order does not matter. That is, 123 and 321 are the same combination.

You also need to consider whether **replacement** is allowed. For example, is 4444 a code allowed by your selection - or can there only be one instance of a 4?

The number of possible ** permutations with replacement** is given by the formula `n^r` where you have

*n*choices and your code is

*r*long. In your example, you have 10 digits and you want a 4 digit code. So there will be `10^4=10000` different codes.

If we want the number of

**, the formula is given by: `(n!)/((n-r)!)` . So in this case: `(10!)/((10-4)!) = 3628800/(6!) = 3628800/720 = 5040` different codes.**

*permutations without replacement*If the **order doesn't matter, **we can use combinations instead of permutations.

The number of **combinations with replacement** is given by `(n!)/((r!(n-r)!))`

in this case the formula gives 210 combinations.

The number of **combinations without replacement** is given by `((n+r-1)!)/((r!(n-1)!))`

in this case, the formula gives 715 combinations.

` `