Skip to content

Instantly share code, notes, and snippets.

@stoneC0der
Last active November 28, 2023 09:38
Show Gist options
  • Save stoneC0der/fd34627369150dd1529f314a6a553efe to your computer and use it in GitHub Desktop.
Save stoneC0der/fd34627369150dd1529f314a6a553efe to your computer and use it in GitHub Desktop.
[Generate random string using Randomizer] #php #random string
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