Problem: I need to get a random element for a container and also delete it from that container. Container does not need to be sorted. I dont care about the order.
vec.erase(vec.begin() + randomIdx);
randomIdx would be between 0 and vec.size()-1
If you want O(1) complexity you could either use the list container for example or swap the element with the last one and delete this instead. ( As mentioned by the others )