in reply to RE: Quicky password sub
in thread Quicky password sub

It's 50% faster on my machine to do this:
{ my @password_chars = ( 0 .. 9, 'A' .. 'Z', 'a' .. 'z' ); my $num_char = @password_chars; sub Pass { my $password = ''; $password .= $password_chars[rand($num_char)] for (1 .. 8); return $password; } }

Replies are listed 'Best First'.
RE: RE: RE: Quicky password sub
by turnstep (Parson) on May 02, 2000 at 22:42 UTC

    You can also just say rand(@password_chars) and get rid of the $num_char variable entirely.

    Also, as long as your are hard coding the iteraction as 'for (1..8)' you can gain even more speed by just doing it like this: (forgive my shortening of password_chars)

    sub Pass { return $p_c[rand(@p_c)] . $p_c[rand(@p_c)] . $p_c[rand(@p_c)] . $p_c[rand(@p_c)] . $p_c[rand(@p_c)] . $p_c[rand(@p_c)] . $p_c[rand(@p_c)] . $p_c[rand(@p_c)]; }
    You could even take out the "return"!
RE: RE: RE: Quicky password sub
by buzzcutbuddha (Chaplain) on May 02, 2000 at 21:31 UTC
    very very cool chromatic. It took me a minute to see the change that
    you made, but wow! cool.