From: Matthew Kerwin Date: 2013-03-07T20:21:21+09:00 Subject: Re: Random#rand_inclusive? --bcaec554dbc8c9b9d604d753e787 Content-Type: text/plain; charset=ISO-8859-1 On 7 March 2013 17:55, Robert Feldt wrote: > > Random#rand and Kernel#rand are exclusive i.e. they return a value >= 0.0 > but 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 --bcaec554dbc8c9b9d604d753e787 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 7= March 2013 17:55, Robert Feldt <robert.feldt@gmail.com> wrote:

Rand= om#rand and Kernel#rand are exclusive i.e. they return a value >=3D 0.0 = but <max if max is a Float. What if one wants a rand that is inclusive o= f the max?

I'm back at a computer now, and have l= ooked up the docs for Random#rand.=A0 Apparently in 2.0 you can simply pass= an inclusive range and it will do what you want, e.g.:=A0 Random.rand(0.0.= .max)=A0 <http://ruby-doc.org/core-2.0/Random.html#method-i-rand>

However in 1.9, yeah, your rand_incl2 is basically what I= 9;d do.=A0 I independently came up with a simplified version: https://gist.github.com/phluid61/51= 07356
--bcaec554dbc8c9b9d604d753e787--