Yes, that's exactly what you are supposed to do. And if it does already exist you can stop generating more numbers because you know at that point how many numbers it took until you got a duplicate...