Last active
April 16, 2018 16:37
-
-
Save colintsteele/e09a6d87013e66e316f7aede0a83d800 to your computer and use it in GitHub Desktop.
great weapon fighting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_avg(die_type, dice_count = 1) | |
rolls = 1_000_000 | |
avg = (1..rolls).inject(0.0) do |acc, _n| | |
dice_count.times do | |
roll = rand(die_type) | |
acc += ( (roll < 3) ? rand(die_type) : roll ) | |
end | |
acc | |
end | |
avg/rolls | |
end | |
puts "1d12 average = #{get_avg(12)}" | |
puts "2d6 average = #{get_avg(6, 2)}" | |
puts "1d10 average = #{get_avg(10)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment