On Mar 12, 2011, at 5:37 AM, Colin Law wrote:
On 12 March 2011 10:10, Erwin <yves_duf...@mac.com> wrote:
I know how to generate a random number between 1 and 2 :
def random
return (1 + rand(2))
end
but let's say I would like to return 1 in 80% of the calls and 2 in
20% of the call...
which library should I use ? ( I've seen a lot at http://raa.ruby-lang.org/
)
No doubt there are better ways but something like
(rand(100) + 120)/100
should do it.
Colin
Well, perhaps something that reveals the intention better:
def usually_one
rand < 0.80 ? 1 : 2
end
-Rob
Rob Biedenharn
r...@agileconsultingllc.com http://AgileConsultingLLC.com/
r...@gaslightsoftware.com http://GaslightSoftware.com/
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.