Last active
November 28, 2023 09:38
-
-
Save stoneC0der/fd34627369150dd1529f314a6a553efe to your computer and use it in GitHub Desktop.
[Generate random string using Randomizer] #php #random string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function generateRandomUniqueId( | |
?string $str = null, | |
?string $prefix = null, | |
?string $suffix = null, | |
int $byte = 16 | |
): string | |
{ | |
$randomizer = new \Random\Randomizer(); | |
$defautl = 'abcdefghijklmnopqrstuvwxyz0123456789'; | |
$defined - $default; | |
$uniqueId = null; | |
if (!is_null($prefix)) { | |
$defined = $str; | |
} | |
$uniqueId = $randomizer->getBytesFromString($defined, $byte); | |
if ($prefix) { | |
$uniqueId = $prefix . $defined; | |
} | |
if ($suffix) { | |
$uniqueId . $suffix; | |
} | |
return $uniqueId; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment