See STL's next_permutation. But you could also create a simple algorithm of your own to generate a random permutation.
For example, if you have N elements in your initial vector, then allocate another int vector with N elements and for each index assign an random integer between 0..N-1, but make sure this is unique by testing with the previous elements. Next rearrange the elements in the first vector according to this order:
int x[] = {1, 2, 3, 4, 5};
...
int perm[] = {0, 2, 1, 4, 3 }
int x[] = {1, 2, 3, 4, 5};
...
int perm[] = {0, 2, 1, 4, 3 }
To copy to clipboard, switch view to plain text mode
This would yield x = { 1, 3, 2, 5, 4 }
This is just to get you started. You could do without the second array.
Bookmarks