xyzio

Archive for the ‘python’ Category

Generating a file filled with random characters in Python

leave a comment »

Generating a file filled with random characters in Python and printing out the elapsed time.

Output goes in tempOut.txt

#!/usr/bin/python

import random
import string
import time

start = time.time()

f = open('tempOut.txt', 'w')

for i in range(0,100000):
    line = ''
    for j in range(0,5000):
        line += str(random.choice(string.letters))

    f.write(line + "n")
    line = ''


f.close()

end = time.time()

print "Elapsed: " + str(end - start)

Written by M Kapoor

September 24, 2014 at 4:58 pm

Posted in python