lib/games_dice/probabilities.rb in games_dice-0.0.6 vs lib/games_dice/probabilities.rb in games_dice-0.1.1
- old
+ new
@@ -92,6 +92,20 @@
end
end
GamesDice::Probabilities.new( h )
end
+ # adding two probability distributions calculates a new distribution, representing what would
+ # happen if you created a random number using the sum of numbers from both distributions
+ def self.add_distributions_mult m_a, pd_a, m_b, pd_b
+ h = {}
+ pd_a.ph.each do |ka,pa|
+ pd_b.ph.each do |kb,pb|
+ kc = m_a * ka + m_b * kb
+ pc = pa * pb
+ h[kc] = h[kc] ? h[kc] + pc : pc
+ end
+ end
+ GamesDice::Probabilities.new( h )
+ end
+
end # class Dice