Is my assumption correct that you would do this as a kind of hotfix? Because thenyou can store the numbers you already have used in another list. So after creating check if it is already part of that list and generate a new one if it has already been use.
For creating a new object you could check the database if that number is already in there and otherwise create a new value.
If you already have a list with all of your objects. You can simply use a ‘find’ list operation after generating the random number to see if it's already known in the list.
But i’m wondering, does it need to be a random number? If you’re just looking for a unique identifier, you can always use the RandomHash java action in the CommunityCommons to generate a unique ID.
Before assigning the generated integer to your object, you could check your database and the list of already created objects (do a ‘find’ on the attribute) to see if its really unique. If yes add to commit list, if not repeat until unique int is generated.