otherwise, it depends on what you mean by "multimensional vector": do you mean an std::vector<std::vector<T>>, a std::vector<T> wrapped in a class with a subscript operator, or storing pointers to rows, etc ... ?
Okay, so it's random rearrangement rather than random selection.
There are two primary approaches you can use:
1) Define a2 in such a way that its memory is contiguous (it is not presently), then use random_shuffle on the entire range. A boost::multi_array is one easy way to do this, or you could use a vector<int> for the underlying data and a vector<int*> to represent the rows. There's lots of material on different ways to define 2D arrays around.
2) Keep a2 as-is, but shuffle a 1D array of 2D indexes into it. For instance,
for (unsigned i = 0; i < inds.size(); ++i)
unsigned row = i/4;
unsigned col = i%4;
a2[row][col] = a[inds[i].first][inds[i].second];
Ahh so there's no classes designed for randomizing vectors like with arrays, shame. Thanks for the help.
That's not correct. random_shuffle() works just as well on a vector as it would on an array. The trouble is, that random_shuffle (and all other STL algorithms) works on a linearly ordered set of iterators, and there is no iterator in the standard library which knows how to traverse over all the T elements in a vector<vector<T>>. Iterating over the elements of a vector is trivial, but iterating over the elements of many vectors as if they're all a single range is not.
That's not to say that such an iterator couldn't be designed, of course. That would be possible. It would need to be a Random Access Iterator to meet the requirements of random_shuffle, of course, but that's doable too with a little more work, especially if you can restrict it to the case when all vectors it operates on are the same length.
My suggestions above were meant to be more intuitive to use than designing a whole new type of iterator, but if you really want to use random_shuffle directly on the object, that's how you do it.