1

I'm searching for an answer to the above problem - how to calculate the probability of getting 3 or more sequential numbers on n number of dice.

I found this formula for 6 six-sided dice here (What are the odds of rolling a 3 number straight throwing 6d6) :

$$ 6^n - 6\cdot4^n + 8\cdot3^n - 3\cdot 2^n \over 6^n $$ However, I can't wrap my head around how to convert this if the die type were changed from d6 to d4s, d8s, or d10s.

Any help would be massively appreciated! Thanking you kindly for taking the time to read this.

Mike Earnest
  • 75,930
GPK
  • 13
  • 1
    Do you want the formula to be for [n]d[n] or for any number of dice of any number of sides? Also do they have to be on consecutive rolls? For example, in the 6d6 case, 242326 contains the straight 234 among its rolls. Does this count? – eyeballfrog Mar 07 '23 at 15:14
  • Any number of dice and any number of sides would be wonderful. The sequence does not matter - for example 4,3,6,4,6,2 would still give the 2,3,4 success (essentially the dice are all being rolled at the same time). – GPK Mar 07 '23 at 15:39
  • 1
    StackExchange has no norm against "necroing" questions. If anything, it is the opposite---new questions are sometimes marked as "duplicates" of older ones. – HighDiceRoller Mar 07 '23 at 20:12
  • Welcome to math.SE! Here's a tutorial and reference for typesetting math on this site. – joriki Mar 07 '23 at 22:56

1 Answers1

0

Icepool

My Icepool Python package can do this computation:

from icepool import d4, d6, d8, d10, d12, Pool
output(Pool([d6, d6, d6, d6, d6, d6]).largest_straight())

You can try it online here.

You can even mix standard die types if you wish. The algorithm is based on representing the evaluation of the roll (in this case, finding the largest straight) as a series of state transitions over the (outcome, count) pairs resulting from the roll of the pool:

def next_state(state, outcome, count):
    best_run, run = state or (0, 0)
    if count >= 1:
        run += 1
    else:
        run = 0
    return max(best_run, run), run

and then using the decomposition of the multinomial as a product of binomials and dynamic programming to find the distribution efficiently. If you are curious to learn more, you can read my paper here.

@inproceedings{liu2022icepool,
    title={Icepool: Efficient Computation of Dice Pool Probabilities},
    author={Albert Julius Liu},
    booktitle={Eighteenth AAAI Conference on Artificial Intelligence and Interactive Digital Entertainment},
    volume={18},
    number={1},
    pages={258-265},
    year={2022},
    month={Oct.},
    eventdate={2022-10-24/2022-10-28},
    venue={Pomona, California},
    url={https://ojs.aaai.org/index.php/AIIDE/article/view/21971},
    doi={10.1609/aiide.v18i1.21971}
}

More examples

You can find the largest count of any outcome, aka largest matching set, aka best X-of-a-kind, by using largest_count():

Pool([d4, d4, d6, d6]).largest_count()

You can only consider dice that rolled certain outcomes by inserting keep_outcomes() or drop_outcomes(), which accept either a function or a collection of outcomes. You can put any evaluation (largest_count(), largest_straight(), etc.) that you want at the end. For example, these drop all 1-5s from the pool:

Pool([d6, d6, d8, d8]).keep_outcomes(lambda x: x >= 6).largest_count()
# equivalently:
Pool([d6, d6, d8, d8]).drop_outcomes([1, 2, 3, 4, 5]).largest_count()

If you want to only filter some of the dice, you can combine multiple pools using the + operator. For example, this combines a pool of 2d6 where only 6s are kept with a pool of 3d8 where everything is kept:

# d6.pool(2) is the same as Pool([d6, d6]).
(d6.pool(2).keep_outcomes([6]) + d8.pool(3)).largest_count()
  • 1
    Fantastic and a big tip of the hat! Very much appreciated – GPK Mar 07 '23 at 23:47
  • 1
    Another huge thank you to HighDicerRoller - Icepool has been a lifesaver. I’ve been looking through the documents to try and figure other commands out, but can’t work out which command to use for working out the probability of mixed dice turning up the same value - for instance, you roll 2d6 and 2d4: looking for the probability breakdown of rolling 3 or more of the same value, but the value itself doesn’t matter (three or more 4s is as good as three or more 2s, for example) – GPK Apr 20 '23 at 01:20
  • For that one you can use Pool([d4, d4, d6, d6]).largest_count(), which will give the probability distribution of the size of the largest matching set, aka "x-of-a-kind". – HighDiceRoller Apr 20 '23 at 02:40
  • 1
    Last double request! How would you input to calculate attaining a certain value (e.g. only 6s on a d6, and 2d8); and how would you figure out a range/numbers of a certain number or above. These last two I can find on many online dice calculators, but as soon as I try to mix die tpyes, it gets messy very quickly. Another big thank you though - Icepool has saved me so much headscratching! – GPK Jun 01 '23 at 14:42
  • I'm not 100% sure I've interpreted your request correctly, but I've added a few more examples. Let me know if this is what you're looking for. – HighDiceRoller Jun 01 '23 at 18:50
  • Apologies for the confusion! It's dawned on me I can use

    Pool([d6, d6, d6, d8]).keep_outcomes(lambda x: x >= 6).largest_count()

    for both situations: I meant for example if 3d6s and 1d8 is rolled, what is the probability of rolling a 6 or higher on all the dice.

    However, your last example has my mind turning with another possiblity to include in the game so another tip of the hat. Thank you so much!

    – GPK Jun 02 '23 at 00:00