question: public static final int randomUnsetBit ( Random r , BitSet bits , final int max ) { if ( bits . cardinality ( ) == max + 1 ) { return - 1 ; } final int candidate = TestUtil . nextInt ( r , 0 , max ) ; if ( bits . get ( candidate ) ) { final int lo = bits . previousClearBit ( candidate ) ; final int hi = bits . nextClearBit ( candidate ) ; if ( lo < 0 && max < hi ) { fail ( "how the hell did we not short circut out? card=" + bits . cardinality ( ) + "/size=" + bits . size ( ) ) ; } else if ( lo < 0 ) { return hi ; } else if ( max < hi ) { return lo ; } return ( ( candidate - lo ) < ( hi - candidate ) ) ? lo : hi ; } return candidate ; }
target:  Given a BitSet, returns a random bit that is currently false, or -1 if all bits are true. NOTE: this method is not fair.