Hi...

As usual, off topic.  :)

Say I have 3 methods a, b, c.   Over the course of many iterations, I
want to call each method a certain percentage of the time.   Say I
have a config file like

method percentage
a 30
b 30
c 40

I'm thinking of writing code that will load up integer ranges like
arange = [1..30]
brange = [31..60]
crange = [61..100]

and then do

many.times do |foo|
num= rand(100)
if num in arange
     a
end
if num in brange
    b
end
if num in crange
end

end #loop


So two questons:
First, is this is a sane approach?  Is there any more elegant way to
call an arbitrary method a certain percentage of the time for a random
number of iterations?

Second, if this is elegant enough, can you suggest a nice way to build
the integer arrays nicely at runtime from the configuration
information?  The only algorithms I can think of turn out pretty ugly.

Thanks...
-Chris
_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to