Search code examples
pythonstringalgorithmrandomletters

How to make a random text python


I need help to output a random text. I've been given a text with 25k words, from this text_file I've been calculating the probability for the single letters, and the single words to see which letters/words have been used most.

Now I need to make a other text with 500 letters, but this text should include the probability that I have calculated, and should be wroten by the letters that I "found" from the first text.

It's like: Text1 -> do probability over the usen letters, which letters have been represented most. Make text2 -> use the probability u found from text1.

Hope u can help me, Im new in Python.


Solution

  • The easiest thing is to randomly select letters of the 25k file. Then the resultant has the same probability as the original.

    import random
    print(''.join(random.choice(original_text) for _ in range(500)))