From 01d5d039f3c91b99377b4635af23e30ece374d0c Mon Sep 17 00:00:00 2001 From: othercorey Date: Sat, 23 May 2020 11:12:46 -0500 Subject: [PATCH] Use random_int with PHP 7 --- lib/Cake/Utility/CakeText.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Utility/CakeText.php b/lib/Cake/Utility/CakeText.php index af2fe45fe..9fc3a65e8 100644 --- a/lib/Cake/Utility/CakeText.php +++ b/lib/Cake/Utility/CakeText.php @@ -30,23 +30,24 @@ class CakeText { * @return string RFC 4122 UUID */ public static function uuid() { + $random = function_exists('random_int') ? 'random_int' : 'mt_rand'; return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', // 32 bits for "time_low" - mt_rand(0, 65535), - mt_rand(0, 65535), + $random(0, 65535), + $random(0, 65535), // 16 bits for "time_mid" - mt_rand(0, 65535), + $random(0, 65535), // 12 bits before the 0100 of (version) 4 for "time_hi_and_version" - mt_rand(0, 4095) | 0x4000, + $random(0, 4095) | 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, + $random(0, 0x3fff) | 0x8000, // 48 bits for "node" - mt_rand(0, 65535), - mt_rand(0, 65535), - mt_rand(0, 65535) + $random(0, 65535), + $random(0, 65535), + $random(0, 65535) ); }