How can I ensure unique discount codes across all price rules?

I have created a private app that creates discount codes and add them under a certain price rule. It works fine except I found that if I add a discount code under that price rule and the code already exists under another price rule I am receiving an error that the code must be unique. Is there a way to avoid this issue? How do I check all the discount codes in all the price rules?