Created
May 4, 2015 12:46
-
-
Save devstopfix/24f59b2f6fbb0d4085eb to your computer and use it in GitHub Desktop.
Dumb Ruby password generator
This file contains hidden or 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
# 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