private static String generateRequest(
      final int n, final Collection<WordCollector> terms_list, final Random random) {
    String result = "";

    final Set<String> stack = Collections.newSet();
    for (; stack.size() < n; ) {
      double d1 = random.nextDouble();
      d1 = FloatMath.power(d1, 1.0);
      int index = (int) (terms_list.size() * d1);
      index = (int) IntegerMath.limit(0, index, terms_list.size());
      final String term = terms_list.getElementAt(index).getWord();
      stack.addAll(JUtils.split(term, " "));
    }
    // stack.print("");
    for (int k = 0; k < stack.size(); k++) {
      result = result + " " + stack.getElementAt(k);
    }

    return result;
  }
示例#2
0
 private static double abs(double f) {
   return FloatMath.abs(f);
 }