diff --git a/includes/common.inc b/includes/common.inc
index 1e287f8..10a587b 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -4911,6 +4911,7 @@ function _drupal_bootstrap_full() {
   require_once DRUPAL_ROOT . '/includes/ajax.inc';
   require_once DRUPAL_ROOT . '/includes/token.inc';
   require_once DRUPAL_ROOT . '/includes/errors.inc';
+  require_once DRUPAL_ROOT . '/includes/uuid.inc';
 
   // Detect string handling method
   unicode_check();
diff --git a/includes/uuid.inc b/includes/uuid.inc
new file mode 100644
index 0000000..563d916
--- /dev/null
+++ b/includes/uuid.inc
@@ -0,0 +1,72 @@
+<?php
+
+/**
+ * @file
+ * Handling of universally unique identifiers.
+ */
+
+/**
+ * Generates an universally unique identifier.
+ *
+ * This function first checks for the PECL alternative for generating
+ * universally unique identifiers. If that doesn't exist, then it falls back on
+ * PHP for generating that.
+ *
+ * @return
+ *   An UUID, made up of 32 hex digits and 4 hyphens.
+ */
+function uuid_generate() {
+  $callback = drupal_static(__FUNCTION__);
+
+  if (empty($callback)) {
+    if (function_exists('uuid_create')) {
+      $callback = '_uuid_generate_pecl';
+    }
+    else {
+      $callback = '_uuid_generate_php';
+    }
+  }
+  return $callback();
+}
+
+/**
+ * Check that a string appears to be in the format of a UUID.
+ *
+ * @param $uuid
+ *  The string to test.
+ *
+ * @return
+ *   TRUE if the string is well formed.
+ */
+function uuid_is_valid($uuid) {
+  return preg_match("/^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/", $uuid);
+}
+
+/**
+ * Generates an universally unique identifier using the PECL extension.
+ */
+function _uuid_generate_pecl() {
+  return uuid_create(UUID_TYPE_DEFAULT);
+}
+
+/**
+ * Generates a UUID v4 using PHP code.
+ *
+ * @see http://php.net/uniqid#65879
+ */
+function _uuid_generate_php() {
+  // The field names refer to RFC 4122 section 4.1.2.
+  return sprintf('%04x%04x-%04x-%03x4-%04x-%04x%04x%04x',
+    // 32 bits for "time_low".
+    mt_rand(0, 65535), mt_rand(0, 65535),
+    // 16 bits for "time_mid".
+    mt_rand(0, 65535),
+    // 12 bits before the 0100 of (version) 4 for "time_hi_and_version".
+    mt_rand(0, 4095),
+    bindec(substr_replace(sprintf('%016b', mt_rand(0, 65535)), '01', 6, 2)),
+    // 8 bits, the last two of which (positions 6 and 7) are 01, for "clk_seq_hi_res"
+    // (hence, the 2nd hex digit after the 3rd hyphen can only be 1, 5, 9 or d)
+    // 8 bits for "clk_seq_low" 48 bits for "node".
+    mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535)
+  );
+}
diff --git a/modules/system/system.test b/modules/system/system.test
index 9944619..cc0e985 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -2466,3 +2466,56 @@ class SystemIndexPhpTest extends DrupalWebTestCase {
   }
 }
 
+/**
+ * Tests uuid.inc and related functions.
+ */
+class UuidTestCase extends DrupalUnitTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'UUID handling',
+      'description' => "Test the handling of universally unique identifiers.",
+      'group' => 'System',
+    );
+  }
+
+  /**
+   * Check to see if a string is a valid UUID.
+   *
+   * @param $uuid
+   *   The string to check.
+   * @param $message
+   *   The message to display along with the assertion.
+   * @param $group
+   *   The type of assertion - examples are "Browser", "PHP".
+   * @return
+   *   TRUE if the assertion succeeded, FALSE otherwise.
+   */
+  protected function assertUuid($uuid, $message = '', $group = 'Other') {
+    return $this->assertTrue(uuid_is_valid($uuid), $message, $group);
+  }
+
+  /**
+   * Test UUID handling.
+   */
+  function testUuidHandling() {
+    // This is a valid UUID, we know that.
+    $valid_uuid = '0ab26e6b-f074-4e44-9da6-1205fa0e9761';
+    $invalid_uuid1 = '0ab26e6b-f074-4e44-9da6-1205fa0e976';
+    $invalid_uuid2 = '0ab26e6b-f074-4e44-9da-1205fa0e9761';
+    // Test the uuid_is_valid() function.
+    $test = (
+      uuid_is_valid($valid_uuid)
+      && !uuid_is_valid($invalid_uuid1)
+      && !uuid_is_valid($invalid_uuid2)
+    );
+    $this->assertTrue($test, 'UUID validation works.');
+
+    // Test generating a UUID.
+    $uuid1 = uuid_generate();
+    $this->assertUUID($uuid1, 'UUID generation works.');
+
+    // Just to demonstrate the purpose of the UUID functionality.
+    $uuid2 = uuid_generate();
+    $this->assertNotEqual($uuid1, $uuid2, 'Same UUID was not generated twice.');
+  }
+}
