- substr: documentation ( source)
- base_convert: documentation ( source)
- microtime: documentation ( source)
- mt_rand: documentation ( source)
- print_r: documentation ( source)
- array_unique: documentation ( source)
- sprintf: documentation ( source)
<?php
function uuid($c = 4) {
$x = function($c) {
for ($n = ''; strlen($n) < $c + 1; $n = $n.base_convert(mt_rand(), 10, 16));
return substr($n, 0, $c);
};
return sprintf(
'%x-%s-%s-%s-%s%s%s',
microtime(true) * 10000, $x($c), $x($c), $x($c), $x($c), $x($c), $x($c)
);
}
$time = microtime();
$uuids = array();
for ($i = 0; $i < 100; $i++) {
$uuids[] = uuid();
}
if (count(array_unique($uuids)) != count($uuids)) {
echo 'DUPLICATED';
} else {
echo 'No duplicate';
print_r($uuids);
}
This script was stopped while abusing our resources