Forums Register Login

Random generator failing

+Pie Number of slices to send: Send
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 !!
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Across multiple JVMs - possibly. Across multiple JVMs running on multiple machines - probably not. What does the documentation say about that?
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2077 times.
Similar Threads
UUID Uniqueness across JVMs
Multiple JVMS?
random number
Session Variable
Two instances of Tomcat on the same OS
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:37:39.