summaryrefslogtreecommitdiffstats
path: root/inc/util.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2017-06-10 16:02:25 +0200
committerSimon Rettberg2017-06-10 16:02:25 +0200
commita087ebf512dafe626179070d4c77e3e69473e424 (patch)
tree29c2b5cd91716a34c32c6719a4cac98a521051aa /inc/util.inc.php
parent[js_jqueryui] Don't override general style; handled by bootstrap (diff)
downloadslx-admin-a087ebf512dafe626179070d4c77e3e69473e424.tar.gz
slx-admin-a087ebf512dafe626179070d4c77e3e69473e424.tar.xz
slx-admin-a087ebf512dafe626179070d4c77e3e69473e424.zip
[inc/Util] Add randomUuid() function
Diffstat (limited to 'inc/util.inc.php')
-rw-r--r--inc/util.inc.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php
index 5d1a4563..697ae3f9 100644
--- a/inc/util.inc.php
+++ b/inc/util.inc.php
@@ -434,4 +434,32 @@ SADFACE;
return $bytes;
}
+ /**
+ * @return string a random UUID, v4.
+ */
+ public static function randomUuid()
+ {
+ $b = unpack('h8a/h4b/h12c', self::randomBytes(12));
+ return sprintf('%08s-%04s-%04x-%04x-%012s',
+
+ // 32 bits for "time_low"
+ $b['a'],
+
+ // 16 bits for "time_mid"
+ $b['b'],
+
+ // 16 bits for "time_hi_and_version",
+ // four most significant bits holds version number 4
+ mt_rand(0, 0x0fff) | 0x4000,
+
+ // 16 bits, 8 bits for "clk_seq_hi_res",
+ // 8 bits for "clk_seq_low",
+ // two most significant bits holds zero and one for variant DCE1.1
+ mt_rand(0, 0x3fff) | 0x8000,
+
+ // 48 bits for "node"
+ $b['c']
+ );
+ }
+
}