Thanks Matthew, didn't know that about 2.0. Cheers, Robert On Thu, Mar 7, 2013 at 12:21 PM, Matthew Kerwin <matthew / kerwin.net.au>wrote: > On 7 March 2013 17:55, Robert Feldt <robert.feldt / gmail.com> wrote: > >> >> Random#rand and Kernel#rand are exclusive i.e. they return a value >= 0.0 >> but <max if max is a Float. What if one wants a rand that is inclusive of >> the max? >> > > I'm back at a computer now, and have looked up the docs for Random#rand. > Apparently in 2.0 you can simply pass an inclusive range and it will do > what you want, e.g.: Random.rand(0.0..max) < > http://ruby-doc.org/core-2.0/Random.html#method-i-rand> > > However in 1.9, yeah, your rand_incl2 is basically what I'd do. I > independently came up with a simplified version: > https://gist.github.com/phluid61/5107356 > -- Best regards, /Robert Feldt -- Tech. Dr. (PhD), Assoc. Professor in Software Engineering Chalmers, Software Engineering Dept Blekinge Institute of Technology, Software Engineering Research Lab robert.feldt (a) chalmers.se or robert.feldt (a) gmail.com Mobile phone: +46 (0) 733 580 580 http://www.cse.chalmers.se/~feldt