First, put your objects in a vector, as you will need random access to them many times:
vector<int> items(itemInTest.begin(), itemInTest.end());
Then, if you need 100 items and you do not want to select the same thing twice, you can just shuffle all of this:
std::random_device rd; std::mt19937 gr(rd()); shuffle(items.begin(), items.end(), gr);
Now just grab the first 100 items. If you want them to be in the set again:
set<int> result(items.begin(), items.begin() + 100);
Or you can use any type of output type you choose - including a vector.
You can do the random_shuffle step again until you finish 100 iterations.
If you don't have C ++ 11, you can use std::random_shuffle() instead of std::shuffle() , noting that the quality of randomness can be reduced. Then you do not need std::mt19937 , just:
random_shuffle(items.begin(), items.end());
source share