Here is an algorithm for permutations with replacement. I modified code from:
http://en.wikipedia.org/wiki/ItoaThis boils down to a radix problem. If you have a set {a,b,c,d,e} and 3 slots, then you have 5^3 radix numbers: aaa, aab, aac, aad, aae, aba, ... . To get all possible unique outcomes, you can have a + operator so that a+1 --> b
...
e+1 --> a with a carry so that, for example:
abe + 1 --> aca
The output is:
Element # Radix Number
1 00
2 10
3 20
4 01
5 11
6 21
7 02
8 12
9 22