Dave's Brain

Browse - programming tips - shuffle 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.

typedef std::vector<std::string>	LINES;

void ShuffleVectorOfStdString(LINES &lines)
{
	srand(time(NULL));
	random_shuffle(lines.begin(), lines.end());
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2010, 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.