- Unsupervised Learning
- Posts
- Percentages of Hitting a Given Number Using x Number of d6’s
Percentages of Hitting a Given Number Using x Number of d6’s
My buddies and I are doing a Harn campaign right now and one of the mechanics involves accruing stat “checks” over time. Every five stat checks you get allows you to roll a single d6. So if you have 15 checks you get to roll 3d6.
The goal is to roll over your stat, which will raise it by one.
So the question of, “when is the best place to roll?” came up. We all know that having more dice makes it more likely, but we wanted to know exactly how much more likely in order to make an informed decision.
Not being overly strong in statistics, I put together the following Ruby code to arrive at the answer using experiment instead of theory.
# Define the sum class class Array; def sum; inject( nil ) { |sum,x| sum ? sum+x : x }; end; end # Define the experiment parameters number_of_d6=9 number_of_runs = 100000 goal = 19 successes = 0 failures = 0 # Program logic number_of_runs.times do rolls = [ ] number_of_d6.times do rolls.push rand(6)+1 end if rolls.sum >= goal successes += 1 else failures += 1 end end # Output print "You ran the experiment #{number_of_runs} times using #{number_of_d6} d6." print "n" print "You succeeded #{successes} times." print "n" print "You failed #{failures} times." print "n" successrate = successes / 1000 print "Your success rate is #{successrate}%."
There is an additional considering that I’m thinking of adding later, which is that when you miss your attempt you lose half the checks you put into it. So it becomes something of an EV equation.
Anyway, if anyone has any comment on how to do this statistically I’d love to hear from you. ::