mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #14624 from cakephp/othercorey-patch-1
Use random_int with PHP 7
This commit is contained in:
commit
9a7c94bad0
1 changed files with 9 additions and 8 deletions
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue