Generating a random number or a random string (UUID) is always a challenge. Even usual java.util.Random
is not perfect. You already ruled out using datbases which would have ensured the randomness across the JVMs.
This problem is on the similar to the challenge faced by web container to generate unique session id. The uniqueness is guaranteed as long as there is single JVM involved. But in real world scenario this is hardly the case. A typical web application is deployed across a cluster of servers. Based on the session id, the load balancer forwards the requests to the appropriate server.
Since the uniqueness of session id is not guaranteed across JVMs, each server appends a unique identifier (e.g. .node1) to the session id which makes sure that even if two server generate same session id, the uniqueness will be preserved by the appended string.
Extending this to your case, you can always put JVM specific identifier in the id, so the generated id might look like,
- 0x-111-111-PX-2013-11-11-00001-M1
- 0x-111-111-PX-2013-11-11-00001-M2
You can put M1/M2 anywhere in the string.
I am not aware of any compulsions (on IDs) you might be having, but this is just a thought.