Generate random numbers : rand « Development « Ruby
- Ruby
- Development
- rand
Generate random numbers
def random_word
letters = { ?v => 'aeiou',
?c => 'bcdfghjklmnprstvwyz' }
word = ''
'cvcvcvc'.each_byte do |x|
source = letters[x]
word << source[rand(source.length)].chr
end
return word
end
puts random_word # => "josuyip"
puts random_word # => "haramic"
Related examples in the same category