public String generateMarkov ( int length , int context , String seed ) { String str = seed ; while ( str . length ( ) < length ) { String prefix = str . substring ( Math . max ( str . length ( ) - context , 0 ) , str . length ( ) ) ; TrieNode node = inner . matchPredictor ( prefix ) ; long cursorCount = node . getCursorCount ( ) ; long fate = CompressionUtil . random . nextLong ( ) % cursorCount ; String next = null ; Stream < TrieNode > stream = node . getChildren ( ) . map ( x -> x ) ; List < TrieNode > children = stream . collect ( Collectors . toList ( ) ) ; for ( TrieNode child : children ) { fate -= child . getCursorCount ( ) ; if ( fate <= 0 ) { if ( child . getChar ( ) != NodewalkerCodec . END_OF_STRING ) { next = child . getToken ( ) ; } break ; } } if ( null != next ) { str += next ; } else { break ; } } return str ; }
Generate markov string .