public String generateRandomStringFromModel(int maxStringLength,String previousChar){
  String newString="";
  do {
    Set<Integer> choices=new HashSet<Integer>();
    choices.addAll(Arrays.asList(0,1,2,3,4,5,6,7,8,9));
    boolean foundValidChar=false;
    String nextChar;
    do {
      int currentChoice=Randomness.choice(choices);
      choices.remove(currentChoice);
      if (previousChar == null) {
        nextChar=languageModel.predict_char(currentChoice);
      }
 else {
        nextChar=languageModel.predict_char(previousChar,currentChoice);
      }
      foundValidChar=nextChar != null && !languageModel.isMagicChar(nextChar);
    }
 while (!choices.isEmpty() && !foundValidChar);
    if (!foundValidChar) {
      logger.debug("Couldn't find any bigram or unigram for " + previousChar);
      nextChar="a";
    }
    if (!languageModel.isEndOfSentence(nextChar))     newString+=nextChar;
    previousChar=nextChar;
  }
 while (newString.length() < maxStringLength && !languageModel.isEndOfSentence(previousChar));
  return newString;
}

public String generateRandomStringFromModel ( int maxStringLength , String previousChar ) { String newString = "" ; do { Set < Integer > choices = new HashSet < Integer > ( ) ; choices . addAll ( Arrays . asList ( 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ) ) ; boolean foundValidChar = false ; String nextChar ; do { int currentChoice = Randomness . choice ( choices ) ; choices . remove ( currentChoice ) ; if ( previousChar == null ) { nextChar = languageModel . predict_char ( currentChoice ) ; } else { nextChar = languageModel . predict_char ( previousChar , currentChoice ) ; } foundValidChar = nextChar != null && ! languageModel . isMagicChar ( nextChar ) ; } while ( ! choices . isEmpty ( ) && ! foundValidChar ) ; if ( ! foundValidChar ) { logger . debug ( "Couldn't find any bigram or unigram for " + previousChar ) ; nextChar = "a" ; } if ( ! languageModel . isEndOfSentence ( nextChar ) ) newString += nextChar ; previousChar = nextChar ; } while ( newString . length ( ) < maxStringLength && ! languageModel . isEndOfSentence ( previousChar ) ) ; return newString ; }
build a random string that is at most maxstringlength characters long .
