Skip to content

Instantly share code, notes, and snippets.

@EvanMu96
Created December 17, 2019 08:27
Show Gist options
  • Save EvanMu96/a5c008f07de60ea49852a5d98f048518 to your computer and use it in GitHub Desktop.
Save EvanMu96/a5c008f07de60ea49852a5d98f048518 to your computer and use it in GitHub Desktop.
vector permutation
tempalte <typename T> struct Vector<T>;
template <typename T> void _in_place_permute(Vector<T> & v)
{
for(int i = v.size(); i > 0; i--)
swap(v[i-1], v[rand()%i); // swap a random element from [0, i) with i
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment