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
For std::unordered_set:
1) take random R in min(s)..max(s)
2) if R in s: return R
3)
newIter = s.insert(R).first;
newIter++;
if (newIter == s.end()) {
newIter = s.begin();
}
auto result = *newIter;
s.erase(R);
return result;
For ordered set (std::set) probability would depend on distance between elements. unordered_set is randomized by hash.
I hope this can help.
PS converting std::set into std::set (where first element in pair is a hash of second) makes this method suitable for any hashable V.