From: Emeka Patrick Date: 2012-06-28T16:44:43+09:00 Subject: Is this the correct use of rand? In the example below why was it necessary to put (max+1)? Couldn't that result in the generation of a random number up to and including 50? This code calls a code blocklimittimes, each time passing in a random number betweenminandmax: def pick_random_numbers(min, max, limit) limit.times { yield min+rand(max+1) } end This code is a wrapper method for pick_random_numbers. It calls a code block 6 times, each time with a random number from 1 to 49: def lottery_style_numbers(&block) pick_random_numbers(1, 49, 6, &block) end lottery_style_numbers { |n| puts "Lucky number: #{n}" } -- Posted via http://www.ruby-forum.com/.