Last active
August 29, 2015 14:11
-
-
Save djtech42/0cfaedf84829b6d1a658 to your computer and use it in GitHub Desktop.
Output Random Words to Terminal
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 random | |
import time | |
def main(): | |
numOfWords = 50 # change this number to modify how many words show up | |
word_file = "/usr/share/dict/words" # word file in Unix | |
words = open(word_file).read().splitlines() # file -> list | |
dup = ""; word = ""; # initialize strings | |
for i in range(numOfWords): | |
while word == dup: # Get new random word. If duplicate word, keep searching for a new word. | |
word = words[random.randrange(len(words))] | |
dup = word | |
print(word) # Output each word on new line | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could publish this a package or CLI tool π you will get my π and share π