I just remembered that there is a macro file that is pretty close to what you want. It is in pg/macros/problemRandomize.pl, and it implements a re-randomize feature. The condition for re-randomizing isn't the one you are looking for, but you should be able to modify it for that. (I'm not sure I'll get to it for a while.)
This macro file was new at the end of the summer, so you might not have it in your copy of pg/macros. If so, you can get it from the CVS repository:
This file is probably a better starting place than the compoundProblem macros.