Module: Wallzilla::Words

Extended by:
Words
Included in:
Words
Defined in:
lib/wallzilla/words.rb

Instance Method Summary collapse

Instance Method Details

#random_word(size_range, window = 4) ⇒ Object

returns: random word from dictionary word list file



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wallzilla/words.rb', line 9

def random_word(size_range, window = 4)
  f = File.open(Wallzilla::Runner.dict_file, 'r')
  fsize = f.size
  loop do
    f.seek(rand(fsize))
    next if f.eof?
    f.readline
    window.times do
      break if f.eof
      w = f.readline.strip
      if size_range.cover? w.size
        f.close
        return w
      end
    end
  end
end