private int nextAvailableIdx(Collection<Integer> startedGrids,int maxTopSize,Random rnd){
  while (true) {
    int idx=rnd.nextInt(maxTopSize);
    if (!startedGrids.contains(idx))     return idx;
  }
}

private int nextAvailableIdx ( Collection < Integer > startedGrids , int maxTopSize , Random rnd ) { while ( true ) { int idx = rnd . nextInt ( maxTopSize ) ; if ( ! startedGrids . contains ( idx ) ) return idx ; } }
gets next available index .
