1 <?php declare(strict_types=1);
16 public static function getBytes(
int $length) : string
19 return random_bytes($length);
20 }
catch (Throwable $ex) {
21 if (!defined(
'PHP_WINDOWS_VERSION_BUILD') && extension_loaded(
'openssl')) {
23 $rand = openssl_random_pseudo_bytes($length, $secure);
24 if (
false !== $rand && $secure ===
true) {
30 for (
$i = 0;
$i < $length; ++
$i) {
31 $rand .= chr(random_int(0, 255));
static getBytes(int $length)
Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.