Create a GUID / UUID in Java
java.util.UUID.randomUUID();
java.util.UUID.randomUUID();
A clustered index on GUID is not a good design. The very nature of GUID is that it’s random, while a clustered index physically orders the records by the key. The two things are completely at odds. For every insert SQL has to reorder the records on disk! Remove clustering from this index! The time … Read more
Why worry about defaults for Guid columns in the database at all? Why not just generate the Guid on the client like any other value. That requires you have a method in your client code that will generate COMB-like guids: public static Guid NewGuid() { var guidBinary = new byte[16]; Array.Copy( Guid.NewGuid().ToByteArray(), 0, guidBinary, 0, … Read more
The following Excel expression evaluates to a V4 GUID: =CONCATENATE(DEC2HEX(RANDBETWEEN(0,4294967295),8),”-“,DEC2HEX(RANDBETWEEN(0,65535),4),”-“,DEC2HEX(RANDBETWEEN(16384,20479),4),”-“,DEC2HEX(RANDBETWEEN(32768,49151),4),”-“,DEC2HEX(RANDBETWEEN(0,65535),4),DEC2HEX(RANDBETWEEN(0,4294967295),8)) -or (depending on locale setting/decimal and list separators)- =CONCATENATE(DEC2HEX(RANDBETWEEN(0;4294967295);8);”-“;DEC2HEX(RANDBETWEEN(0;65535);4);”-“;DEC2HEX(RANDBETWEEN(16384;20479);4);”-“;DEC2HEX(RANDBETWEEN(32768;49151);4);”-“;DEC2HEX(RANDBETWEEN(0;65535);4);DEC2HEX(RANDBETWEEN(0;4294967295);8)) Note that the first character of the third group is always 4 to signify a V4 (pseudo-random number generated) GUID/UUID per RFC 4122 section 4.4. Also note that the first character of the fourth group is … Read more
Since Windows 2000 Microsoft uses a version 4 algorithm: With Windows 2000, Microsoft switched to version 4 GUIDs, since embedding the MAC address was viewed as a security risk. 1 You can see that as well from a GUID generated in .NET (from Wikipedia): Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx with any hexadecimal digits … Read more
in my case most ids will be generated within a large number of mobile clients, not within a limited set of servers. I wonder if in this case, there is a justified concern. That sounds like very bad architecture to me. Are you using a two-tier architecture? Why would the mobile clients have direct access … Read more
It depends on how you format the Guid: Guid.NewGuid().ToString() = 36 characters (Hyphenated) outputs: 12345678-1234-1234-1234-123456789abc Guid.NewGuid().ToString(“D”) = 36 characters (Hyphenated, same as ToString()) outputs: 12345678-1234-1234-1234-123456789abc Guid.NewGuid().ToString(“N”) = 32 characters (Digits only) outputs: 12345678123412341234123456789abc Guid.NewGuid().ToString(“B”) = 38 characters (Braces) outputs: {12345678-1234-1234-1234-123456789abc} Guid.NewGuid().ToString(“P”) = 38 characters (Parentheses) outputs: (12345678-1234-1234-1234-123456789abc) Guid.NewGuid().ToString(“X”) = 68 characters (Hexadecimal) outputs: {0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x9a,0xbc}}
Updated Answer This is now something you can do natively in JavaScript/TypeScript with crypto.randomUUID(). Here’s an example generating 20 UUIDs. for (let i = 0; i < 20; i++) { let id = crypto.randomUUID(); console.log(id); } Original Answer There is an implementation in my TypeScript utilities based on JavaScript GUID generators. Here is the code: … Read more
You can try the following: function GUID() { if (function_exists(‘com_create_guid’) === true) { return trim(com_create_guid(), ‘{}’); } return sprintf(‘%04X%04X-%04X-%04X-%04X-%04X%04X%04X’, mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535)); } Source – com_create_guid
UUIDs/GUIDs are specified by RFC4122. Although Version 4 UUIDs are created from random numbers Section 6 makes an explicit statement on security: Do not assume that UUIDs are hard to guess; they should not be used as security capabilities (identifiers whose mere possession grants access), for example. A predictable random number source will exacerbate the … Read more