added word choosing method

This commit is contained in:
user 2022-01-21 18:05:38 -05:00
parent cfccae02cd
commit 8c74032a3d

View File

@ -4,8 +4,22 @@
#load in dictionary file
#select random word between 5 and 12 letters long
a = Array.new
dictionary = File.open('5desk.txt')
dictionary.each do |row|
a.push(row)
puts row
def pick_word(a)
rand_int = rand(0..a.size)
return a[rand_int].chop!
end
#loading file into an array
dict = File.open('5desk.txt')
dict.each do |row|
a.push(row)
end
#picking a word between 5 and 12 characters long
word = pick_word(a)
until word.length.between?(5, 12)
word = pick_word(a)
end
puts "Your word is #{word}"