I need a probability calculation script that works with various dice and dice pool sizes, that accounts for a mechanic that allows you to reroll up to X dice that are failures, but ONLY once per die. For example, if your dice pool is 5d10, and you roll four successes, you only get one reroll no matter how many rerolls you actually have. Essentially, I am trying to determine if a "limited" rerolls mechanic could be considered equivalent in usefulness compared to directly increasing your dice pool, or if there is a significant difference in the power level of these two mechanics.
This should be fairly simple for the right person, but I am no good at probability nor at using Troll or Anydice, so here I am. Thanks in advance.