generate uuids correctly :p
This commit is contained in:
parent
3b5687adf0
commit
54c41068cf
1 changed files with 5 additions and 2 deletions
7
uuid.php
7
uuid.php
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
/* VanillaUUID v1.0 by abbieoverflight.
|
/* VanillaUUID v1.0.1 by abbieoverflight.
|
||||||
* Licenced under the EUPLv1.2.
|
* Licenced under the EUPLv1.2.
|
||||||
* https://git.colean.cc/threeoh6000/vanillauuid */
|
* https://git.colean.cc/threeoh6000/vanillauuid */
|
||||||
function randomLongHex() {
|
function randomLongHex() {
|
||||||
|
@ -9,7 +9,10 @@ function randomLongHex() {
|
||||||
|
|
||||||
function genUuid4() {
|
function genUuid4() {
|
||||||
$template = randomLongHex();
|
$template = randomLongHex();
|
||||||
$buildup = substr($template, 0, 8) . "-" . substr($template, 8, 4) . "-4" . substr($template, 13, 3) . "-1" . substr($template, 17, 3) . "-" . substr($template, 20, 12);
|
|
||||||
|
$ri = random_int(0b1000, 0b1011);
|
||||||
|
$encoded_byt = dechex((int)$ri);
|
||||||
|
$buildup = substr($template, 0, 8) . "-" . substr($template, 8, 4) . "-4" . substr($template, 13, 3) . "-" . $encoded_byt . substr($template, 17, 3) . "-" . substr($template, 20, 12);
|
||||||
|
|
||||||
return $buildup;
|
return $buildup;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue