Generating a random number that lies between 5000 and 10000...hmmmm. You could generate a number and check if it's in that range. If so, keep it. If not, generate a new number. As far tracking which ones have been used, you could create a database table that holds those numbers. Make that field the primary key and force it to become unique. If the number is already in the table, generate a new number.
This begs the question, "Why are you generating random numbers and trying to limit their range?" If they have to meet one of 4999 possibilities, why not just start with 1 and increment by one when you need a new number?
Hank