code: public static <T> T getRandomElement(Set<? extends T> set, Random rg){
          Iterator<? extends T> it = set.iterator();
          int r = rg.nextInt(set.size());
          T selected = it.next();
          for(int i=0; i<r; i++){
              selected = it.next();
          }
          return selected;
      }
docs: Select a random element from a given set (uniformly distributed). This implementation generates
  a random number r in [0,|set|-1] and traverses the set using an iterator, where the element obtained
  after r+1 applications of {@link Iterator#next()} is returned. In the worst case, this algorithm has
  linear time complexity with respect to the size of the given set.
  
  @param <T> type of randomly selected element
  @param set set from which to select a random element
  @param rg random generator
  @return random element (uniformly distributed)