Skip to content

Instantly share code, notes, and snippets.

@devstopfix
Created May 4, 2015 12:46
Show Gist options
  • Save devstopfix/24f59b2f6fbb0d4085eb to your computer and use it in GitHub Desktop.
Save devstopfix/24f59b2f6fbb0d4085eb to your computer and use it in GitHub Desktop.
Dumb Ruby password generator
# Returns an enumerator that generates password from the standard dictionary
# Only parameter is the number of words to use.
# Example: passwordy(2).next -> "GarlicUngulp"
def passwordy(wc=4)
words = File.readlines('/usr/share/dict/words')
.select {|w| w.size>5 && w.size<=9}
.shuffle
Enumerator.new do |yielder|
yielder.yield(words
.take(wc)
.map {|w| w.chomp.capitalize}
.join)
words = words.drop(wc)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment