You can log the generated number into a data type and then have a condition with a count looking up the newly generated number to see if it has been generated before. Depends on volume but could be rather slow. The second one is to allow collisions and for example you do the check when You insert a record into the table and if the number exists then then regenerate. The likelihood of collisions is low.