What is GUID/UUID?
==================

A GUID (Globally Unique Identifier) or UUID (Universally Unique Identifer)
is a 128-bit value that is supposed to be unique across time and space
dimension. This means that if you create a GUID, it will be different from
another GUID previously created, or from GUID created by someone else on a
different computer, even at the same time.

A GUID is usually represented by hexadecimal notation like this:

 {24cb2bdc-e604-809f-fb74-077c201e009e}
 24cb2bdc-e604-809f-fb74-077c201e009e
 24cb2bdce604809ffb74077c201e009e

There are various algorithms to generate GUID, including one that uses MAC
address and current timestamp, and one that uses random number. The Ruby
Guid library uses the latter.


What is the difference between GUID and UUID?
=============================================

None except the name. GUID is how Microsoft calls UUID, and it seems to be
the more popular one because Microsoft uses GUID/UUID extensively.


What is GUID good for?
======================

It is primarily used to generate primary key for database tables, or for
some sort of ID that needs to be globally unique (like in P2P applications
or in distributed computing).

What makes GUID especially useful is that you can create it autonomously. If
instead of GUID you use a two-part ID (local ID + node ID), or a
hierarchical ID (like DNS or public IP address), then you need to contact
another node or some sort of numbering authority.


Is GUID really globally unique?
===============================

Yes, you can say it's statistically unique, meaning that the chance of
duplicate GUIDs are very, very, very small. The chance of generating two
same GUIDs consecutively are 2^-128 (2.9e-39). Even If your table contains a
billion rows, the chance of creating a GUID that collides with an existing
primary key is 2.9e-30. To appreciate the scale, the chance of GUID
collision is:

* about the same as 16 random people that you put into a room all having the
  same birthday (assuming the birthday distribution is uniform);
* smaller than your computer parts (harddisk, RAM) failing;
* smaller than you winning a multistate lottery;
* smaller than you winning a multistate lottery twice!
* smaller than you being struck by a lightning multiple times!

So for most practical purposes, you can assume it's unique. If you are still
not convinced, try generating 1 million (or 100 millions) of GUIDs using the
Ruby Guid library and try finding a duplicate. If you do find one, consider
yourself very, very, very lucky (or unlucky :-).

But actually, GUID is not mathematically unique. Meaning the probability of
duplication is not exactly zero, just a very small number.


But isn't GUID produced using MAC address really unique?
========================================================

Not really. MAC addresses have been known to be not unique. Many cards also
allow their MAC addresses to be set. This, along with the problem of clock
rewinding, is probably one of the reasons why Microsoft switched their GUID
algorithm to using random number instead. (Another reason is the complaint
that using MAC address raises privacy concern).


Why do you use /dev/urandom instead of /dev/random?
===================================================

Because /dev/random blocks.


