Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-01

GUIDs under FreeBSD don't seem very random

2 messages · 1 person · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

I use GUID's as my primary key values in databases. tiOPF uses the following FPC functions to do this

  CreateGUID(lGUID);
  Result := GUIDToString(lGUID);

I just noticed this difference between two of my databases.

The following GUID's were generated a few minutes ago by FPC (under FreeBSD) when I imported some data.

43E119C8-B404-11E5-9B6C-C86000E37EB0
4421FB17-B404-11E5-9B6C-C86000E37EB0
445D3112-B404-11E5-9B6C-C86000E37EB0
449D1010-B404-11E5-9B6C-C86000E37EB0
44D8951B-B404-11E5-9B6C-C86000E37EB0
45225928-B404-11E5-9B6C-C86000E37EB0
455D0C9D-B404-11E5-9B6C-C86000E37EB0
45984546-B404-11E5-9B6C-C86000E37EB0

Another database of mine has GUID's as follows (records were created in 2011).

151A5024-B075-4331-B12D-FBD686AC4E19
37379F54-B5A7-4702-9A85-74253E2DC91E
F62EE551-B4F1-4319-855A-EBFAF85BD17F
E5F99902-92FC-46C1-944F-0F284592158B
E4974D41-D5CD-4E0E-B943-F243DC300FF6
FF59C912-DE67-4EEA-BDFE-F7E4DEB41640
DD9B17EA-720F-43E7-814A-E06946024810

Note that the second (older) set of GUID's are much more random. Unfortunately I don't know what OS platform I used to generate that data
- I think in was under a Linux system.

My initial thought was that FPC 3.0 changed something, but then I recompiled by application with FPC 2.6.4 (FreeBSD) and imported some more data. The new GUID's generated appeared like the first set under both FPC 2.6.4 and 3.0 using FreeBSD.

Remark:
The first set don't appear to be very random - this is my worry. I'm about it import about 1-2 million records using a FreeBSD system. Is it something I need to worry about?

Why is the one set of GUID's much more random looking than the others? I'm assuming FPC uses different algorithms depending on the OS platform. The FPC help seems to suggest this too.

I just remembered about a *nix console tool "uuidgen" and ran it a couple of times on my FreeBSD system. The GUID's (or UUID's - not sure the difference) have the exact same format as the first set of GUID's above. So I'm assuming FPC is using FreeBSD's UUID generator under FreeBSD, so that would explain the similarity to the uuidgen tool.

From Wikipedia (GUID vs UUID)

-----------------------------
The term GUID usually refers to Microsoft's implementation of the Universally Unique Identifier (UUID) standard.

So am I to assume that I will still get unique values even if I generate 1-2 million records in succession?

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys
Graeme Geldenhuys wrote
From Wikipedia (GUID vs UUID) ----------------------------- The term GUID usually refers to Microsoft's implementation of the Universally Unique Identifier (UUID) standard.

Reading further on Wikipedia I now understand you get different versions of UUID's. My first set of values were Version 1 (MAC address & date-time) type, and the second set was a Version 4 (Random) set.

That explains why they looked so different.

So am I to assume that I will still get unique values even if I generate 1-2 million records in succession? From the Wikipedia explanation on how Version 1 UUID's are generated I

think it is safe to assume that generating 1-2 million UUID's (aka GUID's) is succession should be fine and the likelihood of duplicates are still extremely small.

Probability of duplicates (also from Wikipedia)
------------------------------------------------
...snip...
To put these numbers into perspective, the annual risk of a given person being hit by a meteorite is estimated to be one chance in 17 billion, which means the probability is about 0.00000000006 (6 × 10−11), equivalent to the odds of creating a few tens of trillions of UUIDs in a year and having one duplicate.

That's odds I'll accept for now. ;-)

[Sorry for the mailing list noise. It seems with my own research (after my initial post) I now managed to answered my own question.]

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email