# AnyDice Function: 3d6, lowest die has floor of 3

I've played around with the code a little, but having some trouble figuring out how to to write a function that rolls 3d6 and if the lowest die result is less then 3, then it changes that die to a 3 first then adds the results.

• Do you want all the dice in the roll to have a minimum of 3, or just the one lowest die to be improved? – Carcer Aug 18 at 17:13

## Use a custom die

If you want all the dice to have a minimum of 3, then this is very easy to do - you'd just specify a custom die instead of the d6:

output 3d{3,3,3,4,5,6}


Since a 1 or 2 would be improved to a 3, that's the same as rolling a d6 that actually has three 3s and then the normal 4, 5, 6.

## Sequence inspection

If you actually only want to improve a single die from the pool, that's a little more complicated, but you can do it with a function:

function: roll DICE:s {
result: 1@DICE + 2@DICE + [highest of 3@DICE and 3]
}

output [roll 3d6]


By casting the rolled dice to a sequence (with :s), we can take advantage of sequence inspection and sorting. By default, Anydice orders a dice roll cast to a sequence in decreasing order, so we know the last die in the sequence will be the lowest roll. We can just add the first two dice and then add the higher of the 3rd die or the value 3, using the built-in "highest of X and Y" Anydice function.

Here's a program which compares rolling 3d6 plainly against both these methods:

function: roll DICE:s {
result: 1@DICE + 2@DICE + [highest of 3@DICE and 3]
}

output 3d6 named "3d6 normal"
output 3d{3,3,3,4,5,6} named "3d6 min 3 all dice"
output [roll 3d6] named "3d6 min 3 one die"

• Perfect, Thanks! I was looking at the second version where only the lowest score is increased up to 3 if it is lower then 3. – Khyodee Aug 18 at 20:49