From: Markus Tarmak Date: 2006-01-20T20:51:32+09:00 Subject: Re: Ruby Quiz #62 Adam Shelly wrote: > On 1/19/06, James Edward Gray II wrote: >> >> Na, that's not odd at all. Just tell yourself .. is inclusive >> and ... is exclusive (with regards to the last member). See how that >> extra dot pushes it off the end there... ;) >> > That part I know. But I expected (1...x) to be exactly equivalent to > (1..x-1) > The difference bit me when I was trying to write a version of rand > that took a range (It would be nice if that was a built-in...). My > first attempt is below, but it returns the wrong results when rng is > an exclusive range. > def rrand rng > rng.first + rand(rng.last-rng.first) > end > > -Adam It's not equivalent because you forgot about floating point numbers. irb(main):001:0> (1...9).include? 8.9 => true -- Posted via http://www.ruby-forum.com/.