code: int[] generateUniformHash(int N, int Max) {
                  if (N > Max)
                          throw new RuntimeException("not possible");
                  int[] ans = new int[N];
                  HashSet<Integer> s = new HashSet<Integer>();
                  while (s.size() < N)
                          s.add(new Integer(this.rand.nextInt(Max)));
                  Iterator<Integer> i = s.iterator();
                  for (int k = 0; k < N; ++k)
                          ans[k] = i.next().intValue();
                  Arrays.sort(ans);
                  return ans;
          }
docs: generates randomly N distinct integers from 0 to Max.