@Override public int[] unrank(){
  if (k == 0)   return new int[0];
  int[] combi=new int[k];
  long rank=count - 1 - currentIndex;
  long e=(n - k) * count / n;
  int t=n - k + 1;
  int m=k;
  int p=n - 1;
  do {
    if (e <= rank) {
      combi[k - m]=n - t - m + 1;
      if (e > 0) {
        rank=rank - e;
        e=m * e / p;
      }
      m--;
      p--;
    }
 else {
      e=(p - m) * e / p;
      t--;
      p--;
    }
  }
 while (m > 0);
  return combi;
}

@ Override public int [ ] unrank ( ) { if ( k == 0 ) return new int [ 0 ] ; int [ ] combi = new int [ k ] ; long rank = count - 1 - currentIndex ; long e = ( n - k ) * count / n ; int t = n - k + 1 ; int m = k ; int p = n - 1 ; do { if ( e <= rank ) { combi [ k - m ] = n - t - m + 1 ; if ( e > 0 ) { rank = rank - e ; e = m * e / p ; } m -- ; p -- ; } else { e = ( p - m ) * e / p ; t -- ; p -- ; } } while ( m > 0 ) ; return combi ; }
this implementation uses the unrankcomb - d algorithm introduced in : kokosinski , zbigniew , and ikki - machi tsuruga . " algorithms for unranking combinations and other related choice functions . " ( 1995 ) .
