我正在阅读Brian W. Kernighan和Rob Pike的《编程实践》一书。第三章提供了一个马尔科夫链方法的算法,它读取源文本并使用它生成“读起来不错”的随机文本(这意味着输出比乱码更接近于正确的英语):
set w1 and w2 to the first two words in the source text
print w1 and w2
loop:
randomly choose w3, one of the successors of prefix w1 and w2 in the source text
print w3
replace w1 and w2 by w2 and w3
repeat loop
我的问题是:当w2和w3的新值在源文本中没有后继时,处理这种情况的标准方法是什么?非常感谢!