For testing data, I am in need of quickly creating large files of random text. I have one solution, taken from here and given below:
import random
import string
n = 1024 ** 2 # 1 Mb of text
chars = ''.join([random.choice(string.letters) for i in range(n)])
with open('textfile.txt', 'w+') as f:
f.write(chars)
My problem is that this takes 653 ms to perform, way too much for my uses.
Is there a faster way to quickly generate text files with random text?