Is there a way to randomly select an element from an std::set
in O(log(n))
or
even better O(1)
time? It doesn't need to have an extremely even distribution, just something fairly random
(though obviously even is better)
Looking at std::set::extract
seems like it might be promising
since it could potentially divide the set
in half in constant time, but I can't find a
good way to identify the nodes close to the root, and the node_type
documentation I could
find doesn't go into much detail.
If all else fails, the contents could be copied to a std::map
with random keys in what I think would
be O(n log(n))
time, which would get me amortized O(log(n))
time, but that is not the preferred solution
since it would require some overhead in the cases where I don't want everything