Created
August 12, 2016 22:53
-
-
Save MBtech/8eceec60f88f538a3e0a4103275f5722 to your computer and use it in GitHub Desktop.
Generating random text with english words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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