In article <20030329063108.GA2300 / math.umd.edu>,
Daniel Carrera  <dcarrera / math.umd.edu> wrote:
>
>Say that you have a hash 'events' whose keys are the events you are 
>interested in and the values are the corresponding weights:
>
>e.g.
>events = { 
>	"event1" => 5, 
>	"event2" => 17, 
>	"event3" => 6, 
>	"event4" => 13
>}
>
>Solution:
>tot = 0; events.each { |event, weight| tot += weight }
>val = rand tot
>event = events.each do |event, weight|
>	val -= weight; 
>	return event if val < 0
>end
>
>This should work, I think.
>

Hmmm.... Wouldn't this be biased by order?

Phil