From: khaines@... Date: 2006-07-13T04:18:01+09:00 Subject: Re: Generating a random floating point number On Thu, 13 Jul 2006, Mauricio Fernandez wrote: > On Thu, Jul 13, 2006 at 12:39:50AM +0900, khaines@enigo.com wrote: >> def fp_rand(limit) >> fl = limit.floor >> rm = limit.remainder(fl) >> rand(fl) + rand(rm) >> end >> >> >> fp_rand(12.73) >> => 10.1895547681143 > > > That method would never return values whose decimal part >= 0.73 in the above > example. > Besides, the variance of the resulting random variable would be lower than > for the correct limit * rand(): > (fl^2 + rm^2) / 12 instead of (fl + rm)^2 / 12 = limit^2 / 12 > Thanks, Mauricio. It's always good to have one's nits picked on occasion. :) Kirk