I'm able to construct a static counter that goes up from 0 to 9999 until it resets again, and use this as a value to make entries unique.
However, this requires referencing an object store when the application shuts down and needs to find where its count was last time it ran. I was hoping to avoid any sort of object stores and rely on random number generation. Something like:
int randomTimeBasedGenerator() {
Random r = new Random(System.currentTimeMillis())
int num = r.nextInt() % 9999
return num
}
But what kind of guarantee do I have that this remains unique? How long would it remain unique? Are there any study papers I can look into for this sort of scenario?
It would be an elegant solution if I can at least guarantee it won't repeat for a couple of weeks or months. Completely useless in my case however if no such guarantee exists.
Aucun commentaire:
Enregistrer un commentaire