On 01.03.2010 20:40, Reiichi Tyrael wrote:
> David Springer wrote:
>> Reiichi Tyrael,
>>
>> Is the range inclusive OR exclusive?
>>
>> Should n1 OR n2 be reurned sometimes or never?
>>
>>> number_to_guess = rand(n1..n2)
> Inclusive!
Sorry, I answered before seeing this email. In that case it should be
irb(main):003:0> low, high = 12, 34
=> [12, 34]
irb(main):004:0> r = low + rand(high + 1 - low)
=> 22
You can also do something like this:
irb(main):012:0> (low..high).to_a.sample
=> 21
irb(main):013:0> (low..high).to_a.sample
=> 27
Although in that case you should store the array somewhere for
efficiency reasons.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/