Assuming that you want to calculate the highest single die roll in the pool of mixed dice, here's one simple solution:
function: max A:n B:n C:n {
result: 1@[sort {A, B, C}]
}
output [max 1@3d4 1@2d6 1@1d8]
This code is also easily extensible; for example, here's the same code with some d12s and a d20 thrown in:
function: max A:n B:n C:n D:n E:n {
result: 1@[sort {A, B, C, D, E}]
}
output [max 1@5d4 1@4d6 1@3d8 1@2d12 1@1d20]
(Note how the results 13–20 all have a probability of 1/20 = 5% in this example: any time you roll above 12 on the single d20, that'll be the highest roll, regardless of what happens with the other dice. For the same reason, the probability of the highest roll being 7 or 8 is always 1/8 = 12.5% in the first example.)
The reason this code works is because the rule that "If a die is provided [to a function expecting a number], then the function will be invoked for all numbers on the die – or the sums of a collection of dice – and the result will be a new die." The built-in notation 1@DIE
returns a (single, biased) die representing the distribution of the highest roll in the original die; the custom [max NUMBER NUMBER NUMBER]
, which just calculates the maximum of three numbers, is then called for each possible combination of maximum rolls, and the results weighed by the probability of the combinations. It's kind of a brute-force method, but it works.
Ps. If you write [max 3d4 2d6 1d8]
instead of [max 1@3d4 1@2d6 1@1d8]
, you get something very different — namely, the maximum sum of each kind of dice. Basically, the 1@
causes the maximum of each of the three rolls to be passed to max
, whereas leaving it out causes the sum each roll to be passed instead. Of course, if you have only one of each kind of die, then this makes no difference.
Also, for basically the same reason, the method described above cannot be easily adapted to give the second highest number in an irregular dice pool. To achieve that, you'll instead need to pass each sub-pool to the function as a sequence, as described here and here.