On 12 March 2011 14:23, Colin Law <[email protected]> wrote:
> On 12 March 2011 13:42, Rob Biedenharn <[email protected]> wrote:
>> def usually_one
>> rand < 0.80 ? 1 : 2
>> end
>
> Yes, much better. I suppose it is the old programmer in me
> instinctively avoiding floating point to save on processor time. A
> bit silly when everything has hardware floating point.
Although I prefer Rob's suggestion as a better example of self
documented code; this is another alternative...
def usually_one
[1,2,2,2,2][rand(5)]
end
...there's many ways to skin a cat :-)
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.