Created
October 14, 2008 16:38
-
-
Save jashmenn/16738 to your computer and use it in GitHub Desktop.
random-pronounceable-strings-in-ruby
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
#!/usr/bin/env ruby | |
# from http://e-huned.com/2008/10/13/random-pronounceable-strings-in-ruby/ | |
require 'rubygems' | |
require 'activesupport' | |
class String | |
def self.random_pronounceable(syllables = 2) | |
alphabet = ('a'..'z').to_a | |
vowels = %w{ a e i o u } | |
consonants = alphabet - vowels | |
returning Array.new do |r| | |
syllables.times do | |
r << consonants.rand | |
r << vowels.rand | |
r << alphabet.rand | |
end | |
r << rand(1000) | |
end.join | |
end | |
end | |
how_long = ARGV[0].to_i > 0 ? ARGV[0].to_i : 2 | |
puts String.random_pronounceable(how_long) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment