Perl - PHP:随机字符串生成

I don't know perl language, but i am trying to customize an application written in perl language. I want to know the logic or meaning of the following perl code. I know this code is for generating a random string, but i want its details i.e i want to know how can i generate this same random string in PHP? Please anyone give me the PHP code for this perl code!!

   sub generate_rand_string {

    #warn "generate_rand_string";

    my $chars = shift
      || 'aAeEiIoOuUyYabcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789';
    my $num = shift || 1024;

    require Digest::MD5;

    my @chars = split '', $chars;
    my $ran;
    for ( 1 .. $num ) {
        $ran .= $chars[ rand @chars ];
    }
    return Digest::MD5::md5_hex($ran);
}

Please anyone help me!!!!

In PHP it would like this:

function generate_rand_string($chars = null, $length = 1024) {
    if($chars == null) {
        $chars = 'aAeEiIoOuUyYabcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789';
    }

    $rand = '';
    for($i = 0; $i < $length; $i++) {
        $rand .= $chars[ rand(0, strlen($chars) - 1) ];
    }

    return md5($rand);
}

Steps for emulating:

  1. accept a string and default to aAeEiIoOuUyYabcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789 if no string is provided
  2. accept a number and default to 1024 if no number is provided
  3. split the string into characters
  4. create a string with random characters selected from the above set of characters
  5. return the hexadecimal representation of the MD5 hash of the string