This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Random generator failing

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !!
 
Sheriff
Posts: 22773
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic