Try this one for PHP 3.0.7 and older. The difference is in the 2nd arguement for some of the calls to the rand() function (in older versions, the 2nd argument was the range instead of the inclusive maximum).
Also, on the first version I posted, the line "if ( $which == 1 ) $password .= rand(0,10);" should have been "
if ( $which == 1 ) $password .= rand(0,9);"
function MakePassword($length = 7)
{
// purpose: return a random password of length $length
srand( (double) microtime() );
$which = "";
$password = "";
for ($i=0; $i < $length; $i++) {
$which = rand(1, 3);
// character will be a digit 2-9
if ( $which == 1 ) $password .= rand(0,10);
// character will be a lowercase letter
elseif ( $which == 2 ) $password .= chr( rand(65, 26) );
// character will be an uppercase letter
elseif ( $which == 3 ) $password .= chr( rand(97, 26) );
}
return $password;
}