def RandomHtml():
    yield '<html><body>'
yield '<body>'
yield RandomBody()
yield '</body></html>'

def RandomBody():
    yield RandomSection()
if random.randrange(2) == 0:
    yield RandomBody()

def RandomSection():
    yield '<h1>'
How to generate random html document