Sunday, January 6, 2013

return random word from array or list



def new_word #returns random word
    words = %w{red blue orange green black white purple grey}
    lenword = words.length
    word_index = rand(1..(lenword -1))
    puts words[word_index]
end

new_word

#=> *new word

No comments:

Post a Comment