dimanche 9 août 2015

Shuffle vector of vectors in C++

Consider a vector<vector<int> > Vec.

I want to shuffle the int values in each vector<int> within Vec and also perform shuffle on vector< vector<int> >.

How do I do this in C++?

My main aim is to randomize a matrix of integers, which I have implemented using vector<vector<int> > Vec.

Currently, I am trying to do this:

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();

for(int i=0;i<Vec.size();i++) {
    shuffle(Vec[i].begin(), Vec[i].end(), std::default_random_engine(seed));
}
shuffle(Vec.begin(),Vec.end()); // gives an error




Aucun commentaire:

Enregistrer un commentaire