The offset starts at 0, so this would work better:
$num = rand(0,26) ;
Here's a function that's simpler than the original and more flexible:
function createRandomPassword($len = 8, $use_uc = false, $use_digits = false)
{
$chars = range('a', 'z');
if ($use_uc) {
$chars = array_merge($chars, range('A', 'Z'));
}
if ($use_digits) {
$chars = array_merge($chars, range('0', '9'));
}
$max_offset = count($chars) - 1;
$pass = '' ;
for ($i = 0; $i < $len; $i++) {
$offset = mt_rand(0, $max_offset);
$pass .= $chars[$offset];
}
return $pass;
}