From d07c15d1e4e6a64f6a773f6381d5216bdef11985 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 22 Dec 2022 12:28:56 +0100 Subject: [PATCH] add uuid function --- Utils/RnG/UUID.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Utils/RnG/UUID.php diff --git a/Utils/RnG/UUID.php b/Utils/RnG/UUID.php new file mode 100644 index 000000000..2e268233d --- /dev/null +++ b/Utils/RnG/UUID.php @@ -0,0 +1,43 @@ + $length Result length in bytes + * + * @return string + * @since 1.0.0 + */ + public static function default(int $length = 16) : string + { + if ($length < 8) { + throw new \InvalidArgumentException(); + } + + return pack('Q', \time()) . ($length > 8 ? \random_bytes($length - 8) : ''); + } +}