Skip to content

Instantly share code, notes, and snippets.

@jashmenn
Created October 14, 2008 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jashmenn/16738 to your computer and use it in GitHub Desktop.
Save jashmenn/16738 to your computer and use it in GitHub Desktop.
random-pronounceable-strings-in-ruby
#!/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