Dave's Brain

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()); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.