#!/usr/bin/python # -*- coding: utf-8 -*- """Minimal FORTRAN-style Markov text generator.""" import sys import random import bisect if __name__ == '__main__': model = [[0 for ii in range(256)] for jj in range(256)] last = -1 for c in sys.stdin.read(): c = ord(c) if last != -1: model[last][c] += 1 last = c for ii in range(256): for jj in range(1, 256): model[ii][jj] += model[ii][jj-1] for ii in range(1024): sys.stdout.write(chr(c)) while model[c][-1] == 0: c = random.randrange(256) c = bisect.bisect_right(model[c], random.randrange(model[c][-1]))