Skip to content

Instantly share code, notes, and snippets.

@MBtech
Created August 12, 2016 22:53
Show Gist options
  • Save MBtech/8eceec60f88f538a3e0a4103275f5722 to your computer and use it in GitHub Desktop.
Save MBtech/8eceec60f88f538a3e0a4103275f5722 to your computer and use it in GitHub Desktop.
Generating random text with english words
import requests
import random
import sys
#Pass the number of lines as the first arguument to the program
n_lines = int(sys.argv[1])
words_low = 10
words_high = 20
word_site = "http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain"
f = open("random_data.txt",'w+')
response = requests.get(word_site)
WORDS = response.content.splitlines()
print len(WORDS)
for i in range(0,n_lines):
string = ''
for j in range(0, random.randint(words_low,words_high)):
string += " " + WORDS[random.randint(0,len(WORDS)-1)]
string += " \n"
print string
f.write(string)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment