I learned this in poker - If you shuffle the cards 7 times, replacing each card behind it with the one in front of it...It is mathematically shuffled. Well that has really no use for your problem. If you don't wanna write the algorithm yourself(that's the funnest part) you can check out the next_permutation function in algorithm.h