forked from xharaken/step2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanagram_generator.py
More file actions
28 lines (25 loc) · 1.02 KB
/
anagram_generator.py
File metadata and controls
28 lines (25 loc) · 1.02 KB
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
import sys, random
def read_words(word_file, min_threshold, max_threshold):
words = []
with open(word_file) as f:
for line in f:
line = line.rstrip('\n')
if (min_threshold <= len(line) and len(line) <= max_threshold):
words.append(line)
return words
def main(word_file, n, min_threshold, max_threshold):
words = read_words(word_file, min_threshold, max_threshold)
# print(len(words))
for i in range(n):
word = words[int(random.random() * len(words))]
characters = list(word)
for j in range(max_threshold - len(characters)):
characters.append(chr(ord('a') + int(random.random() * 26)))
assert(len(characters) == max_threshold)
random.shuffle(characters)
print(''.join(characters))
if __name__ == "__main__":
if len(sys.argv) != 5:
print("usage: %s word_file n min_threshold max_threshold" % sys.argv[0])
exit(1)
main(sys.argv[1], int(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4]))