You are looking for a permutation algorithm.