• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Random generator failing

 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have used a fairly good random generator that was working well on test environment.

Our random generator started failing in an environment having 4 jvm. And sometimes generated numbers that were same ? Tha'ts quite possible when you have multiple JVMs and alot of invocations to the random generator at the same time across different JVM. One in a billion chance of getting the same random numbers but we are seeing instances of this issue.

So i was wondering whats the best way out to generate a random unique id ?

I came across UUID generation and wanted to poll this group if they have used UUID's and have encountered the same scenarios as we are ? If you did encounter random generation failing across multiple jvms what did you use to prevent it ? Please point me to some good material for the same too.

I can provide more details if required !!
 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
madhup narain wrote:And sometimes generated numbers that were same ? Tha'ts quite possible when you have multiple JVMs and alot of invocations to the random generator at the same time across different JVM. One in a billion chance of getting the same random numbers but we are seeing instances of this issue.

With each random number generator it's possible to get the same number multiple times. After all, it's random. If you flip a coin twice, can you guarantee that you'll get both heads and tails once? Or if you flip more that the numbers of heads and tails are the same?

So i was wondering whats the best way out to generate a random unique id ?

First of all, stop using real random numbers. Random does not guarantee unique.

I was going to suggest UUID but it seems like you already encountered it.
 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. We are using Java 1.4 and seems like UUID came with Java 1.5
There are however some projects like the JUG'S UUID i could actually use.
They have something like

I wanted to know if the simple generateTimeBasedUUID() would actually generate me Unique identifiers across multiple JVMS.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Across multiple JVMs - possibly. Across multiple JVMs running on multiple machines - probably not. What does the documentation say about that?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic