in reply to Random Password Generator

That is very nice and simple unlike a lot of other ones i have seen here at the monastery. *THUMBS UP*

Replies are listed 'Best First'.
Re^2: Random Password Generator
by merlyn (Sage) on Jul 01, 2005 at 14:08 UTC
    It is simpler than many, but still unecessarily complicated, because of the amount of repeated code.

    Presuming you want 3 each of the lowercase, uppercase, and digits, you can simplify the code to:

    my @ranges = ([a..z]) x 3, ([A..Z]) x 3, ([0..9]) x 3; my $password; while (@ranges) { $range = splice @ranges, rand @ranges, 1; # random pick $password .= $range->[rand @$range]; # random pick from the range }
    The whole thing of $password = join "", $password, ... in the original post is definitely worth unlearning if nothing else. {grin}

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Or even simpler:

      @chr = (0..9,'A'..'Z','a'..'z'); print @chr[rand @chr] for 1..9;

      but you don't get anymore the 3-3-3 pattern, which IMHO, isn't a big deal anyway.

        but you don't get anymore the 3-3-3 pattern, which IMHO, isn't a big deal anyway.

        Depending on what you're using the passwords for it could be a big deal since the 3-3-3 pattern dramatically reduces the space of possible passwords, making a brute force attack more feasible.

        Restricting the format of passwords is almost always a bad idea security wise.

      This was actually a little experiment. I know the more practical way would be to use arrays, like in your post. I was just trying to find the best way to do it using only strings. :o)
      I'm the original anon poster.. (-- I'll make an account one of these days) and umm.. what variable in your improvement is the password at the end? I can't seem to work it out. I know, I know. I'm dumb.