UUID: Universally Unique Identifier

A Universally Unique Identifier (UUID) is a 128 bit number generated by an algorithm that tries to make the UUID unique from all other UUIDs.

A UUID consists of 32 hexadecimal digits. It is typically displayed in groups of characters with dashes.

Example UUID:

  be257fd5-bf13-40a0-89e9-9d0874c4829e

UUID generation with Unix uuidgen

To generate a random UUID on most versions of Unix, use the uuigen command:

  $ uuidgen -r
  2510dcad-7f6e-44a6-a116-e9508c1fe3eb

UUID generation with Perl Data::UUID

To generate a random UUID using Perl, use the Data::UUID class:

  use Data::UUID;
  $ug = new Data::UUID;
  $str = $ug->create_str();
  print $str . "\n";
  #=> "4F0B066D-CF73-4980-97EF-8EB9A62FD590"

UUID generation with Ruby SecureRandom

To generate a random UUID using Ruby, use the SecureRandom class:

  require 'securerandom'
  puts SecureRandom.uuid
  #=> "4f0b066d-cf73-4980-97ef-8eb9a62fd590"



What's Next?

blog comments powered by Disqus