Version 1 UUID is meant for generating time-based UUIDs. They also accept 48 bit long identifier (281,474,976,710,655 available values). In many cases it make sense to use a machine MAC Address as an identifier. Sometimes if we use several UUID generators on the same system, we can just use configured identifiers. It is very important to have unique identifier in a distributed environment. That will guarantee conflict-free ids.
Version 4 UUID is meant for generating UUIDs from truly-random or pseudo-random numbers. UUID v4 are not giving us guaranteed unique numbers; they are rather practically unique. Probability of getting a duplicate is as follows:
所以Version4 UUID是有機率是重覆的Only after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%
作者實測 Java 1.7 java.util.UUID 是Version 4 UUID
UUID idOne = UUID.randomUUID();
System.out.println("UUID One: " + idOne + ", version = " + idOne.version());
=> UUID One: 4de87030-2cd6-4547-b2fd-9280d1cb22de, version = 4
也就是說, 是有機率性是重覆的
沒有留言:
張貼留言