Skip to content

Commit

Permalink
utilizes Random\Randomizer in PHP 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 17, 2024
1 parent fba3961 commit fc8db11
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Utils/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Nette\Utils;

use Nette;
use Random\Randomizer;


/**
Expand Down Expand Up @@ -37,6 +38,8 @@ public static function generate(int $length = 10, string $charlist = '0-9a-z'):
throw new Nette\InvalidArgumentException('Length must be greater than zero.');
} elseif ($chLen < 2) {
throw new Nette\InvalidArgumentException('Character list must contain at least two chars.');
} elseif (PHP_VERSION_ID >= 80300) {
return (new Randomizer)->getBytesFromString($charlist, $length);
}

$res = '';
Expand Down

0 comments on commit fc8db11

Please sign in to comment.