Skip to content

Instantly share code, notes, and snippets.

@colintsteele
Last active April 16, 2018 16:37
Show Gist options
  • Save colintsteele/e09a6d87013e66e316f7aede0a83d800 to your computer and use it in GitHub Desktop.
Save colintsteele/e09a6d87013e66e316f7aede0a83d800 to your computer and use it in GitHub Desktop.
great weapon fighting
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