Created
December 20, 2010 00:37
-
-
Save anolson/747875 to your computer and use it in GitHub Desktop.
Create random pronounceable strings
This file contains 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
module RandomPronounceableString | |
VOWELS = "aeiou" | |
CONSONANTS = "bcdfghjklmnprstvwyz" | |
def random_pronounceable | |
%(#{random_consonant}#{random_vowel}#{random_consonant}#{random_vowel}#{random_consonant}#{random_vowel}) | |
end | |
def random_vowel | |
random_letter(VOWELS) | |
end | |
def random_consonant | |
random_letter(CONSONANTS) | |
end | |
def random_letter(letters) | |
letters[rand(letters.length)].chr | |
end | |
end |
This file contains 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
require 'test/unit' | |
require 'random_pronounceable_string' | |
class RandomPronounceableStringTest < Test::Unit::TestCase | |
include RandomPronounceableString | |
def test_random_pronounceable | |
assert_not_equal random_pronounceable, random_pronounceable | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment