Or You can implement Your own using constructor new UUID(long mostSigBits, long leastSigBits) from core Java. Please see package from artifact java-uuid-generator. There is also 3rd party implementation from FasterXML Generators.timeBasedGenerator().generate() that is based on time and MAC address, too. Please see package 4j.core.util from artifact log4j-core. You can use 3rd party implementation from Log4j UuidUtil.getTimeBasedUuid() that is based on the current timestamp, measured in units of 100 nanoseconds from October 10, 1582, concatenated with the MAC address of the device where the UUID is created. Instead of a version 4 (random based) I would advice You to use version 1 (time based). It's random and therefore a collision will occur, definitely, as confirmed others in comments above/below that detected collisions very early. The UUID is generated using a cryptographically strong pseudo random number generator. Static factory to retrieve a type 4 (pseudo randomly generated) UUID. The probability of one duplicate would be aboutĥ0% if every person on earth owns 600 million UUIDs. The next 100 years, the probability of creating just one duplicate Other words, only after generating 1 billion UUIDs every second for One chance in 17 billion, which means the probability is aboutĠ.00000000006 (6 × 10−11), equivalent to the odds of creating a few tens of trillions of > UUIDs in a year and having one duplicate. The annual risk of someone being hit by a meteorite is estimated to be Out of a total of 128īits, four bits are used for the version ('Randomly generated UUID'),Īnd two bits for the variant ('Leach-Salz').Ĭhance of two having the same value can be calculated using Randomly generated UUIDs have 122 random bits. If you get a UUID collision, go play the lottery next.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |