src/EventCentric/Identity/UuidIdentity.php
private static function uuid4()
    {
        $bytes =
            function_exists('openssl_random_pseudo_bytes')
                ? openssl_random_pseudo_bytes(16)
                : self::generateBytes(16);


        $hash = bin2hex($bytes);

        // Set the version number
        $timeHi = hexdec(substr($hash, 12, 4)) & 0x0fff;
        $timeHi &= ~(0xf000);
        $timeHi |= 4 << 12;

        // Set the variant to RFC 4122
        $clockSeqHi = hexdec(substr($hash, 16, 2)) & 0x3f;
        $clockSeqHi &= ~(0xc0);
        $clockSeqHi |= 0x80;

        $fields = [
            'time_low' => substr($hash, 0, 8),
            'time_mid' => substr($hash, 8, 4),
            'time_hi_and_version' => sprintf('%04x', $timeHi),
            'clock_seq_hi_and_reserved' => sprintf('%02x', $clockSeqHi),
            'clock_seq_low' => substr($hash, 18, 2),
            'node' => substr($hash, 20, 12),
        ];

        return vsprintf(
            '%08s-%04s-%04s-%02s%02s-%012s',
            $fields
        );
    }
private static function uuid4()
    {
        $bytes =
            function_exists('openssl_random_pseudo_bytes')
                ? openssl_random_pseudo_bytes(16)
                : self::generateBytes(16);


        $hash = bin2hex($bytes);

        // Set the version number
        $timeHi = hexdec(substr($hash, 12, 4)) & 0x0fff;
        $timeHi &= ~(0xf000);
        $timeHi |= 4 << 12;

        // Set the variant to RFC 4122
        $clockSeqHi = hexdec(substr($hash, 16, 2)) & 0x3f;
        $clockSeqHi &= ~(0xc0);
        $clockSeqHi |= 0x80;

        $fields = [
            'time_low' => substr($hash, 0, 8),
            'time_mid' => substr($hash, 8, 4),
            'time_hi_and_version' => sprintf('%04x', $timeHi),
            'clock_seq_hi_and_reserved' => sprintf('%02x', $clockSeqHi),
            'clock_seq_low' => substr($hash, 18, 2),
            'node' => substr($hash, 20, 12),
        ];

        return vsprintf(
            '%08s-%04s-%04s-%02s%02s-%012s',
            $fields
        );
    }
private static function uuid4 ( ) { $ bytes = function_exists ( 'openssl_random_pseudo_bytes' ) ? openssl_random_pseudo_bytes ( 16 ) : self :: generateBytes ( 16 ) ; $ hash = bin2hex ( $ bytes ) ; // Set the version number $ timeHi = hexdec ( substr ( $ hash , 12 , 4 ) ) & 0x0fff ; $ timeHi &= ~ ( 0xf000 ) ; $ timeHi |= 4 << 12 ; // Set the variant to RFC 4122 $ clockSeqHi = hexdec ( substr ( $ hash , 16 , 2 ) ) & 0x3f ; $ clockSeqHi &= ~ ( 0xc0 ) ; $ clockSeqHi |= 0x80 ; $ fields = [ 'time_low' => substr ( $ hash , 0 , 8 ) , 'time_mid' => substr ( $ hash , 8 , 4 ) , 'time_hi_and_version' => sprintf ( '%04x' , $ timeHi ) , 'clock_seq_hi_and_reserved' => sprintf ( '%02x' , $ clockSeqHi ) , 'clock_seq_low' => substr ( $ hash , 18 , 2 ) , 'node' => substr ( $ hash , 20 , 12 ) , ] ; return vsprintf ( '%08s-%04s-%04s-%02s%02s-%012s' , $ fields ) ; }
Returns a version 4 UUID
@return string
Returns a version 4 UUID