phrase = inputchars for (words = 10000; words > 0; words--) l = -1 u = nword while l+1 != u m = (l + u) / 2 if wordncmp(word[m], phrase) < 0 l = m else u = m for (i = 0; wordncmp(phrase, word[u+i]) == 0; i++) if rand() % (i+1) == 0 p = word[u+i] phrase = skip(p, 1) if strlen(skip(phrase, k-1)) == 0 break print skip(phrase, k-1)
Example 2: The complete pseudocode puts an upper bound on the number of words it generates.