From: Robert Klemme Date: 2013-03-07T18:31:05+09:00 Subject: Re: Random#rand_inclusive? On Thu, Mar 7, 2013 at 8:55 AM, Robert Feldt wrote: > Random#rand and Kernel#rand are exclusive i.e. they return a value >= 0.0 > but the max? Would any of the below approaches guarantee to give an inclusive > range? I don't think there is any good way to achieve that for floats. You could try rounding but this would effectively mean to reduce the number of significant decimals. def rand_incl(float, decimals = 10) rand(float).round(decimals) end I would have to reason a bit longer about what that does to statistical distribution of values. It might still not be exactly evenly distributed - especially since the edge values have fewer values to round to (i.e. negatives are missing and values >= max). Nah, forget it: does not look like a good idea. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/