private function _generateUUIDFromData($data)
    {
        $data = substr($data, 0, 16);

        $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set the '4' in block 3
        $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits for block 4

        return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
    }
private function _generateUUIDFromData($data)
    {
        $data = substr($data, 0, 16);

        $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set the '4' in block 3
        $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits for block 4

        return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
    }
private function _generateUUIDFromData ( $ data ) { $ data = substr ( $ data , 0 , 16 ) ; $ data [ 6 ] = chr ( ord ( $ data [ 6 ] ) & 0x0f | 0x40 ) ; // set the '4' in block 3 $ data [ 8 ] = chr ( ord ( $ data [ 8 ] ) & 0x3f | 0x80 ) ; // set bits for block 4 return vsprintf ( '%s%s-%s-%s-%s-%s%s%s' , str_split ( bin2hex ( $ data ) , 4 ) ) ; }
Generate a valid UUIDv4 from provided random data.

A UUIDv4 is formatted
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
where x is 0-9, A-F and y is 8-9, A-B.

@param $data     string  random bytes.

@return string           valid, formatted UUIDv4
Generate a valid UUIDv4 from provided random data .