<?php
function random_password(int $min, int $max)
{
$allowed = array_merge(
[33, 60, 62, 94, 95],
range(48, 57),
range(64, 90),
range(97, 122)
);
$length = random_int($min, $max);
$chars = [];
for ($i = 0; $i < $length; $i++) {
$bi = random_int(0, count($allowed)-1);
$chars[] = chr($allowed[$bi]);
}
return implode('', $chars);
}
var_dump(random_password(8, 12));
preferences:
32.79 ms | 402 KiB | 5 Q