What is a good way to get a [pseudo-]random element from an STL range?
The best I can come up with is to do std::random_shuffle(c.begin(), c.end())
an
You can try to get a random number between 0 and the number of elements of the container. You could then access to the corresponding element of the container. For example, you can do this:
#include
#include
// ...
std::srand(std::time(0)); // must be called once at the start of the program
int r = std::rand() % c.size() + 1;
container_type::iterator it = c.begin();
std::advance(it, r);