UUID — oracle-tech

    Forum Stats

  • 3,702,038 Users
  • 2,239,552 Discussions
  • 7,835,729 Comments

Discussions

UUID

captain_kirkcaptain_kirk Posts: 2
edited May 2016 in Java Desktop Applications

I am new to these forums and I apologize if I am posting this in the wrong place.

I recently introduced UUID's with UUID.randomUUID() into a program that required unique filenames. I was impressed by this capability. However I was challenged about this by one person who claims that these ids are not unique. Below is a URL regarding UUID. I will now need to read in a value from an ini file, a very slow laborious process to "guarantee" uniqueness because of one person's misunderstanding about this. Is there any proof that UUID is unique? Thanks, jetMan.

Java Practices -> Generating unique IDs

Best Answer

  • handathandat Posts: 4,688
    edited May 2016 Accepted Answer

    The UUID is pseudo unique since the random function it uses for randomisation is also only pseudo random. So yes, if you want to be very pedantic about it, then it is not absolutely guranteed to be random and unique. But it depends on what you really need it for and how does reading a value from an ini file make it more unique? What kind of value is in your ini file and how will it make it unique? Reading some value from an ini file is trivial though.

    For your reference, here's the gnu classpath equivalent of the UUID class. It is not the same, but does the same thing: http://fuseyism.com/classpath/doc/java/util/UUID-source.html

Answers

  • handathandat Posts: 4,688
    edited May 2016 Accepted Answer

    The UUID is pseudo unique since the random function it uses for randomisation is also only pseudo random. So yes, if you want to be very pedantic about it, then it is not absolutely guranteed to be random and unique. But it depends on what you really need it for and how does reading a value from an ini file make it more unique? What kind of value is in your ini file and how will it make it unique? Reading some value from an ini file is trivial though.

    For your reference, here's the gnu classpath equivalent of the UUID class. It is not the same, but does the same thing: http://fuseyism.com/classpath/doc/java/util/UUID-source.html

  • captain_kirkcaptain_kirk Posts: 2
    edited May 2016

    Thanks for the link handat. I agree that reading from an ini file does nothing for uniqueness. Right now I am just putting a 'j' character in the ini and append it to a unique vendor file name to resolve a dupe file issue. Since UUID generates a (supposedly) unique id every time, it provides more uniqueness than reading 'j' from an ini. But sigh, it's not up to me how this is done, I just code this .

This discussion has been closed.