I need a little help with a probability calculation in anydice. We are making a fudge based game using 4 fudge dice, so basically a d3 system: -1,0,1

We are allowing your attribute or stats in the game go to go from -3 to 4 and high stats allows you to reroll a dice.

So basically on any fudge roll a character can reroll a number of dice up to his stat maximum. If he has a negative stat he has to take away dice from the initial roll.

I figured out how to determine the probabilities of rolling with 4 dice and lower representing a negative stat:

`output 4d{-1,0,1} `

What I need help with is determining the probability of rerolling a dice when a character has a positive stat.

An example of what I am talking about: My fighter has a 1 strength and I roll my 4 fudge dice I get 3 blanks and 1 – on the dice. I decide to reroll the 1 – to try and get a better result on the second roll.

A formula I tried in any dice to represent the example above is `4d{-1,0,1}-1`

The problem with this forumla is it only works if the second reroll is better their is a possibility the second reroll will be the same so it does not quite work.

Does anyone have some insight on a way I can make a proper formula in anydice to represent a reroll of 4 fate dice with the possibility of 1-4 dice being rerolled and the possibility that the second reroll has only a 66% chance of being better than the first reroll.

I am making assumptions that a player will only reroll dice if they have a negative appear on the fudge dice.