Skip to content

Instantly share code, notes, and snippets.

@ricardotealdi
Last active February 11, 2018 11:50
Show Gist options
  • Save ricardotealdi/8b7c043ab8393c5930db to your computer and use it in GitHub Desktop.
Save ricardotealdi/8b7c043ab8393c5930db to your computer and use it in GitHub Desktop.
Simple Pronounceable Word Generator in Ruby
class WordGenerator
VOGALS = %w(a e i o u y)
CONSONANTS = [*?a..?z] - VOGALS
MOD_RESULT = [0, 1].freeze
def initialize(length)
@length = length
@mod_result = MOD_RESULT.sample
end
def generate
length.times.map { |i| i % 2 == mod_result ? CONSONANTS.sample : VOGALS.sample }.join
end
private
attr_reader :length, :mod_result
end
# 100.times.each { puts WordGenerator.new(10).generate }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment