import random

database = {}
# ... Fill the database...

def speak():
    # Start with a random word
    words = [random.choice(database.keys())]
    # We'll stop with a probability of 0.05
    while random.random() > 0.05:
        # Get the successors of the last word.
        # successors = TODO

        # If there is no successor, stop.
        if len(successors) == 0:
            break

        # Otherwise, add one random successor
        # to the list of words
        # words.append( TODO )

    # Finally concatenate the list of words
    # and return it.
    return ' '.join(words)

for i in range(5):
    print speak()