private char chooseNextCharacter(final IntUnaryOperator randomInRange,final String sequence) throws NoSuchElementException {
  final Map<Character,Integer> probabilities=sequenceProbabilities.get(sequence);
  if (probabilities == null) {
    throw new NoSuchElementException("There are no computed probabilities for the specified key.");
  }
  Integer highestProbability=null;
  final List<Character> highestStrings=new ArrayList<>();
  for (  final Map.Entry<Character,Integer> entry : probabilities.entrySet()) {
    if (highestProbability == null) {
      highestStrings.add(entry.getKey());
      highestProbability=entry.getValue();
    }
 else {
      if (entry.getValue() > highestProbability) {
        highestStrings.clear();
        highestStrings.add(entry.getKey());
        highestProbability=entry.getValue();
      }
 else {
        highestStrings.add(entry.getKey());
      }
    }
  }
  final int randomIndex=randomInRange.applyAsInt(highestStrings.size());
  return highestStrings.get(randomIndex);
}

private char chooseNextCharacter ( final IntUnaryOperator randomInRange , final String sequence ) throws NoSuchElementException { final Map < Character , Integer > probabilities = sequenceProbabilities . get ( sequence ) ; if ( probabilities == null ) { throw new NoSuchElementException ( "There are no computed probabilities for the specified key." ) ; } Integer highestProbability = null ; final List < Character > highestStrings = new ArrayList < > ( ) ; for ( final Map . Entry < Character , Integer > entry : probabilities . entrySet ( ) ) { if ( highestProbability == null ) { highestStrings . add ( entry . getKey ( ) ) ; highestProbability = entry . getValue ( ) ; } else { if ( entry . getValue ( ) > highestProbability ) { highestStrings . clear ( ) ; highestStrings . add ( entry . getKey ( ) ) ; highestProbability = entry . getValue ( ) ; } else { highestStrings . add ( entry . getKey ( ) ) ; } } } final int randomIndex = randomInRange . applyAsInt ( highestStrings . size ( ) ) ; return highestStrings . get ( randomIndex ) ; }
determines the character to follow the specified sequence using the precomputed probabilities of which characters most often appear after the specified sequence .
