Skip to content

Instantly share code, notes, and snippets.

@djtech42
Last active August 29, 2015 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djtech42/0cfaedf84829b6d1a658 to your computer and use it in GitHub Desktop.
Save djtech42/0cfaedf84829b6d1a658 to your computer and use it in GitHub Desktop.
Output Random Words to Terminal
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()
@poliveira89
Copy link

You could publish this a package or CLI tool 😃 you will get my 👍 and share 👅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment