This question with an added constraint.
I\'m willing to allow not-uniform selection as long as it\'s not to lop sided.
Given that \"sets are typically imple
I don't see how to do it with just std::set
, so you probably need a different data structure. Like Victor Sorokin said, you can combine a set with a vector. Instead of set
, use map
, plus vector< map
. The value for each key is an index into the vector, and each element of the vector points back to the map element. The vector elements have no particular order. When you add an element, put it at the end of the vector. When you remove an element and it's not the last one in the vector, move the last element to the deleted element's position.