-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandWords.py
More file actions
executable file
·58 lines (35 loc) · 962 Bytes
/
Copy pathrandWords.py
File metadata and controls
executable file
·58 lines (35 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import string
import textwrap
import codecs
import random
class NotASCII(Exception): pass
WORDCOUNT = 5000
dictFile = codecs.open("/usr/share/dict/en_US.dic", "r", encoding="utf-8")
dictWords = []
for i in dictFile:
i = i.strip()
try:
for j in i:
if j not in string.ascii_lowercase:
raise NotASCII
except NotASCII:
continue
if len(i) > 10 or len(i) < 3:
continue
dictWords.append(i)
chosenWords = []
wordcount = 0
while wordcount != WORDCOUNT: # hurr same name
nextWord = random.randrange(0, len(dictWords) )
newWord = dictWords.pop(nextWord)
chosenWords.append(newWord)
wordcount += 1
if len(dictWords) == 0:
break
wrapper = textwrap.TextWrapper()
wrapper.width = 80
wrappedText = wrapper.wrap("""{{"{0}"}}""".format("\", \"".join(chosenWords) ) );
for line in wrappedText:
print(line)