Измените свой метод и добавьте необходимые символы явно :
function randomPassword() {
$letter = "abcdefghijklmnopqrstuwxyz";
$upperLetters = "ABCDEFGHIJKLMNOPQRSTUWXYZ";
$numbers = "0123456789";
$signs = '$_.@!^%&*()-#';
$pass = array(); //remember to declare $pass as an array
// add a letter
$pass[] = $letters[rand(0, strlen($letters) - 1)];
// add an uppercase letter
$pass[] = $letters[rand(0, strlen($upperLetters) - 1)];
// add number and sign
$pass[] = $letters[rand(0, strlen($numbers) - 1)];
$pass[] = $letters[rand(0, strlen($signs) - 1)];
// add more chars
$alphabet = $letters . $upperLetters . $numbers . $signs;
for ($i = 0; $i < $yourLength; $i++) {
$n = rand(0, strlen($alphabet) - 1);
$pass[] = $alphabet[$n];
}
// shuffle chars in array so your passwords not always start with letter
shuffle($pass);
return implode($pass); //turn the array into a string
}
echo randomPassword();
Далее:
function randomPassword() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789$_.@!^%&*()-#";
$pass = array(); //remember to declare $pass as an array
// numbers here are start and end positions of symbols groups
$pass[] = $alphabet[rand(0, 25)];
$pass[] = $alphabet[rand(26, 51)];
$pass[] = $alphabet[rand(52, 61)];
$pass[] = $alphabet[rand(62, 74)];
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < $yourLength; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
shuffle($pass);
return implode($pass); //turn the array into a string
}
echo randomPassword();