aspose file tools*
The moose likes Java in General and the fly likes Random generator failing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Random generator failing" Watch "Random generator failing" New topic
Author

Random generator failing

madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
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 !!


Money for nothing and Java for Free
SCJP, SCWCD
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
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

Joined: Oct 14, 2008
Posts: 1337
Across multiple JVMs - possibly. Across multiple JVMs running on multiple machines - probably not. What does the documentation say about that?
 
 
subject: Random generator failing