1

  • Does the java.util.UUID is unique in each file?

    For example:

    • We have file IDFile1.java, generating here a random id, using UUID.randomUUID().toString().
    • And we have file2 with name IDFile2.java, which generates another id.

    Will this two file IDs collide with each other?

  • Is there any way to "turn back" used ID, generated from java.util.UUID, that will mean, this ID could be used again?
  • 1
    • As the name suggests, UUID is universally unique. Without more knowledge about the class itself I would suggest the collision would be at least very rare, if theoretical. Commented Dec 3, 2013 at 21:09

    2 Answers 2

    1

    The purpose of functions like randomUUID is to munge together various pieces of information which are likely to have some amount of randomness such that two UUIDs generated at different times or in different places would have an extremely small likelihood of matching unless all sources of potential randomness happened to yield identical results. No effort is made to keep track of which UUIDs have or have not been issued; instead, the goal is to have enough randomness that the probability of an unintentional match will be small relative to e.g. the probability of a computer being smashed to a million pieces by a meteor strike.

    Note that the system may use "number of UUIDs issued" as part of its UUID calculation, but that would only be one of many factors that go into it. The purpose of such a counter isn't to allow one to "go back" to a previous UUID, but rather to ensure that if e.g. two UUIDs are requested nearly simultaneously without any source of randomness having become available between them, the two requests will yield different values.

    Sign up to request clarification or add additional context in comments.

    Comments

    0

    UUIDs are unrelated to what file generates it. It doesn't matter which file generates them they more than likely will not be the same.

    For question 2 the way UUIDs are generated doesn't really allow for them to be regenerated in any meaningful way. They are usually generated based on some info from your computer, the current time and other stuff. The Java algorithm uses a cryptographically secure random number generator and are known as type 4 UUIDs.

    1 Comment

    So it means, that generated ID isn`t checked like "is used" in UUID class? And there is extremely low probability, that it will generate two identical ID in a sequence?

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.