Technically, what you want to do is generate all permutations of a given ordered tuple. Why don't you read the wiki on "permutations" and see if something useful comes out...
The fool hath said in his heart, There is a God. They are corrupt, they have done abominable works, there is none that doeth good.
Psalm 14, KJV revised edition