On Wed, 12 Jul 2006, jamiethehutt wrote:

> I'm a Ruby newbie and I'm wondering if there's a simple way to generate
> a random floating point number, I want to generate numbers between 0
> and about 2-3.6 with the max changing each time (an example max would
> be 3.26861475366199).
>
> I'm hoping there's something simpler than generating an integer
> (rand(3)) and then generating a point (rand(0.268)) and adding them
> together...
>
> Thanks for any advice you can give!

def fp_rand(limit)
   fl = limit.floor
   rm = limit.remainder(fl)
   rand(fl) + rand(rm)
end


fp_rand(12.73)

=> 10.1895547681143


Kirk Haines