randomblob(16) generates 16 random bytes.

randomblob(16) does not generate a valid UUID (it does not set the version and 
variant flags in the resulting 16-bytes of random data).  If you set the 
version to 4 and the variant to 1 then randomblob(16) does produce valid 
version 4 uuids with 122-bits of randomness.  The ext/misc/uuid.c extension 
does this, for example, generating valid version 4 variant 1 UUIDs.

The only other useful type of UUID to generate would be version 1.  Version 1 
is a pseudo-sequential clock based value in which the last 48-bits are the MAC 
address of the computer (or some fixed identifier of 48-bits for the computer) 
with the variant set appropriately (thus chopping a couple of bits) and the MAC 
type (thus chopping another bit, to identify whether the origin is a "real MAC 
unicast address" or a "fake ID -- multicast MAC address").  The clock and 
sequence is merely the current clock count plus a sequence number of the 
generated UUID.  Less the 4 bit version which is set to 1.

Microsoft does not generate valid UUIDs (either version 1 or version 4).  They 
do not have the version and variant set properly and are stored "little endian" 
rather than in network byte order.  If you pass a "standards based" UUID to a 
"Microsoft" renderer you will get a different result than if you pass the same 
UUID bytes to a standards compliant renderer.

Both version 1 and version 4 UUIDs are probabilisticly Universally Unique.  
Version 1 because the single-source generator uses a theoretically unique 
machine ID, and version 4 because hopefully the random 122-bits are in fact 
122-bits of entropy.

So really it boils down to a question of how you want these UUIDs to be 
represented.  There is the "Microsoft way" and the "Microsoft way" is 
incompatible with the "standard".  So if you choose the "standard" way, then 
you will have to forgo the "Microsoft way" and use only standard compliant 
handlers (and therefore will have standard compliant UUIDs on all platforms).  
Conversely, if you choose the "Microsoft way" then you will be limited to only 
ever being compliant with the "Microsoft way" and limited to Microsoft 
platforms.

-- 
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.

>-----Original Message-----
>From: sqlite-users <sqlite-users-boun...@mailinglists.sqlite.org> On
>Behalf Of Andy KU7T
>Sent: Thursday, 20 February, 2020 11:12
>To: SQLite mailing list <sqlite-users@mailinglists.sqlite.org>
>Subject: [sqlite] Is randomblob(16) a good guid generation across
>multiple computers?
>
>Hi,
>I added a randomblob(16) to each record of a Sqlite table via a trigger
>with the goal of global uniqueness. Is that the correct approach or would
>it be better to pass Guid from .Net? I am using System.Data.Sqlite. The
>following article got me questioning the usage of randomblob:
>https://devblogs.microsoft.com/oldnewthing/20120523-00/?p=7553
>
>Thanks
>Andy
>
>Sent from my T-Mobile 4G LTE Device
>Get Outlook for Android<https://aka.ms/ghei36>
>_______________________________________________
>sqlite-users mailing list
>sqlite-users@mailinglists.sqlite.org
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to