Skip to content

Commit 9df8380

Browse files
committed
migrated from cryptographically secure random numbers to fast random numbers
1 parent 17cff6e commit 9df8380

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Traits/HasNameTrait.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use function bin2hex;
66
use function ceil;
7+
use function mt_rand;
78
use function openssl_random_pseudo_bytes;
89
use function random_bytes;
910
use function substr;
@@ -46,7 +47,11 @@ private function generateName(string $prefix = 'var', int $length = null): strin
4647
{
4748
$length ??= self::$automaticVariableLength;
4849

49-
return $prefix . substr(bin2hex(random_bytes($length)), 0, $length);
50+
$random = '';
51+
for ($i = 0; $i < $length; ++$i) {
52+
$random .= dechex(mt_rand(0, 15));
53+
}
54+
return $prefix . $random;
5055
}
5156

5257
private function configureName(?string $givenName, string $prefix, int $length = null): void

0 commit comments

Comments
 (0)