Browse - Programming Tips - How do I randomize the order (shuffle) an std::vector of std::string ?

Date: 2009Oct11
Language: C/C++

Q.  How do I randomize the order (shuffle) an std::vector of std::string ?

A.  Here's a function that does it.

#include <string> #include <vector> #include <algorithm> typedef std::vector<std::string> LINES; void ShuffleVectorOfStdString(LINES &lines) { srand(time(NULL)); random_shuffle(lines.begin(), lines.end()); }