2048) throw new InvalidArgumentException('Length'); $groups = ['abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789', '!@#$%^&*()-_=+']; $pool = implode('', $groups); $out = ''; foreach ($groups as $group) $out .= $group[random_int(0, strlen($group)-1)]; while (strlen($out) < $length) $out .= $pool[random_int(0, strlen($pool)-1)]; for ($i = strlen($out)-1; $i > 0; $i--) { $j = random_int(0, $i); [$out[$i], $out[$j]] = [$out[$j], $out[$i]]; } return $out; }