#!/usr/bin/env python
import string
import random
out_file = 'text_file.txt'
file_size = 1024 * 1024
rands = lambda x: ''.join(random.choice(string.letters + string.digits) for x in xrange(x))
with open(out_file, 'w') as f:
f.write(rands(file_size))