public static function randomHex(): string
{ return bin2hex(self::
randomBytes());
} /**
* same as Ramsey\Uuid\UuidFactory->uuidFromBytesAndVersion without using a transfer object
*/
public static function randomBytes(): string
{ if (self::
$generator === null
) { self::
$generator =
new UnixTimeGenerator((new RandomGeneratorFactory())->
getGenerator());
} $bytes = self::
$generator->
generate();
/** @var array<int> $unpackedTime */
$unpackedTime =
unpack('n*',
substr($bytes, 6, 2
));
$timeHi =
(int) $unpackedTime[1
];
$timeHiAndVersion =
pack('n*', BinaryUtils::
applyVersion($timeHi, 7
));
/** @var array<int> $unpackedClockSeq */
$unpackedClockSeq =
unpack('n*',
substr($bytes, 8, 2
));
$clockSeqHi =
(int) $unpackedClockSeq[1
];