PHP random password generator

Here is a PHP script I wrote to generate passwords.

<?php
function passwordCreate($length = 8) {
  if ($length>62 || $length<1) $length = 8;
  $chars = array();
  for ($i=0; $i<$length; $i++) {
    do {
      $r = rand(48, 122);
    }
    while (($r>57 && $r<65) || ($r>90 && $r<97) || in_array(chr($r),$chars));
      $chars[] = chr($r);
  }
  return implode('', $chars);
}
?>

Updated: