Gonna have to be more specific... just want a random number generated, that isnt the same as one already made, or what?
posted 16 years ago
Yes, basically a random number that can be assigned as an id, a number not already assigned. In PHP there's a function called uniqueID() and I've been unable to unearth anything that approximates that in JAVA, so I was wondering if there are any preferred routines to do this.
To clarify: The id I want to generate is for a product_id field in a database, as I prefer not to rely on the auto_incrementing primary key. I perhaps gave the impression I was looking for a session id...sorry.
Originally posted by Peter Simard: The id I want to generate is for a product_id field in a database, as I prefer not to rely on the auto_incrementing primary key.
Why? It seems to me as if the database was in the best position to guarantee the uniqueness of a key. Random numbers are - by definition - not unique. You always had to check them against the database.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
She'll be back. I'm just gonna wait here. With this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java