public static <T>T rand(final Set<T> set){
  final int n=rand(set.size());
  int i=0;
  for (  final T element : set) {
    if (i == n) {
      return element;
    }
    i++;
  }
  return null;
}

public static < T > T rand ( final Set < T > set ) { final int n = rand ( set . size ( ) ) ; int i = 0 ; for ( final T element : set ) { if ( i == n ) { return element ; } i ++ ; } return null ; }
given a set of any type , returns an arbitrary element , using an equal distribution . generics are used so that the returned element will have the same type as the set ' s elements have . note : this is not very efficient . if you need to do this on large sets several times per second , consider copying the set contents to an array , then call rand ( ) on this array .
