Code

<?php
function randomPassword() {
$alphabet = “abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789”;
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) – 1; //put the length -1 in cache
$r = rand(8, 20);
for ($i = 0; $i < $r; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}

echo randomPassword();
?>