Question: better way to come up with new constant of integration to use?

many times I have an expression with constant of integrations in it and need to integrate., So need to make sure to add a new constant of integration which is not already used.

Currently I do this

restart;
sol:=x-_C1*x+_C3*x^2;
myconstants:=indets(sol,And(symbol, suffixed(_C, nonnegint)));
map(X->String(X),myconstants);
map(X->X[3..],%);
map(X->:-parse(X),%);
n:=max(%);
new_constant:=_C||(n+1);

This make _C4 as the new constant. 

This assumes all constants have form _Cn which is what I use. It finds all _Cn's then converts each to string, then remove _C part from the string leaving the number, then find the maximum one and adds 1 to it to generate new constant to use,

Is there a better way to do this? Even though the above works, I have feeling there might be better way.

Please Wait...