public static <T> T pickRandom (Iterator<T> iter, int count, Random r)
    {
        if (count < 1) {
            throw new IllegalArgumentException(
                "Must have at least one element [count=" + count + "]");
        }

        for (int ii = 0, ll = getInt(count, r); ii < ll; ii++) {
            iter.next();
        }
        return iter.next();
    }
public static < T > T pickRandom ( Iterator < T > iter , int count , Random r ) { if ( count < 1 ) { throw new IllegalArgumentException ( "Must have at least one element [count=" + count + "]" ) ; } for ( int ii = 0 , ll = getInt ( count , r ) ; ii < ll ; ii ++ ) { iter . next ( ) ; } return iter . next ( ) ; }
Picks a random object from the supplied iterator (which must iterate over exactly
<code>count</code> objects using the given Random.

@param r the random number generator to use.

@return a randomly selected item.

@exception NoSuchElementException thrown if the iterator provides fewer than
<code>count</code> elements.