This is not the way to do it.
Let your database create the numbers using the auto_increment or 'serial' properties of the primary key of your table.
That way you can just create a new row in the table and the database will create a new unique id and give it back to you.
Never try to make a unique id by yourself, because that's impossible in a multi-user environment.