Skip to content

Commit ef96485

Browse files
committed
[String] Leverage Randomizer::getBytesFromString()
1 parent 3d0a988 commit ef96485

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

ByteString.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\String;
1313

14+
use Random\Randomizer;
1415
use Symfony\Component\String\Exception\ExceptionInterface;
1516
use Symfony\Component\String\Exception\InvalidArgumentException;
1617
use Symfony\Component\String\Exception\RuntimeException;
@@ -55,6 +56,10 @@ public static function fromRandom(int $length = 16, ?string $alphabet = null): s
5556
throw new InvalidArgumentException('The length of the alphabet must in the [2^1, 2^56] range.');
5657
}
5758

59+
if (\PHP_VERSION_ID >= 80300) {
60+
return new static((new Randomizer())->getBytesFromString($alphabet, $length));
61+
}
62+
5863
$ret = '';
5964
while ($length > 0) {
6065
$urandomLength = (int) ceil(2 * $length * $bits / 8.0);

0 commit comments

Comments
 (0)